use std::fmt::Display; use async_trait::async_trait; use gamenight_api_client_rs::apis::default_api::locations_get; use inquire::{ui::RenderConfig, Select}; use crate::flows::{exit::Exit, view_location::ViewLocation}; use super::*; #[derive(Clone)] pub struct ListLocations { } impl ListLocations { pub fn new() -> Self { Self {} } } #[async_trait] impl<'a> Flow<'a> for ListLocations { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { let locations = locations_get(&state.api_configuration).await?; let mut flows = locations.into_iter().map(|location| -> Box { Box::new(ViewLocation::new(location.into())) }).collect::>>(); flows.push(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 ListLocations { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "List all locations") } }