gamenight/gamenight-cli/src/flows/gamenight_menu.rs

49 lines
1.2 KiB
Rust

use inquire::{ui::RenderConfig, Select};
use crate::flows::{add_gamenight::AddGamenight, exit::Exit, games::Games, list_gamenights::ListGamenights};
use super::*;
#[derive(Clone)]
pub struct GamenightMenu {
}
impl GamenightMenu {
pub fn new() -> Self {
Self {}
}
}
unsafe impl Send for GamenightMenu {
}
#[async_trait]
impl<'a> Flow<'a> for GamenightMenu {
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
let flows: Vec<Box<dyn Flow + Send>> = vec![
Box::new(ListGamenights::new()),
Box::new(AddGamenight::new()),
Box::new(Games::new()),
Box::new(Exit::new())
];
let choice = Select::new("What would you like to do?", flows)
.with_help_message("Select the action you want to take or quit the program")
.with_render_config(RenderConfig {
option_index_prefix: inquire::ui::IndexPrefix::Simple,
..Default::default()
})
.prompt_skippable()?;
self.continue_choice(state, &choice).await
}
}
impl Display for GamenightMenu {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Main menu")
}
}