diff --git a/harmony-rs/examples/tui/Cargo.toml b/harmony-rs/examples/tui/Cargo.toml new file mode 100644 index 0000000..d9390ca --- /dev/null +++ b/harmony-rs/examples/tui/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "example-tui" +edition = "2024" +version.workspace = true +readme.workspace = true +license.workspace = true +publish = false + +[dependencies] +harmony = { path = "../../harmony" } +harmony_tui = { path = "../../harmony_tui" } +harmony_types = { path = "../../harmony_types" } +cidr = { workspace = true } +tokio = { workspace = true } +harmony_macros = { path = "../../harmony_macros" } +log = { workspace = true } +env_logger = { workspace = true } +url = { workspace = true } diff --git a/harmony-rs/examples/tui/src/main.rs b/harmony-rs/examples/tui/src/main.rs new file mode 100644 index 0000000..660d593 --- /dev/null +++ b/harmony-rs/examples/tui/src/main.rs @@ -0,0 +1,19 @@ +use harmony::{ + inventory::Inventory, + maestro::Maestro, + modules::dummy::{ErrorScore, PanicScore, SuccessScore}, + topology::HAClusterTopology, +}; + +#[tokio::main] +async fn main() { + let inventory = Inventory::empty_inventory(); + let topology = HAClusterTopology::dummy(); + let mut maestro = Maestro::new(inventory, topology); + maestro.register_all(vec![ + Box::new(SuccessScore {}), + Box::new(ErrorScore {}), + Box::new(PanicScore {}), + ]); + harmony_tui::init(maestro).await.unwrap(); +} diff --git a/harmony-rs/harmony_tui/src/lib.rs b/harmony-rs/harmony_tui/src/lib.rs index 96b6e99..64dda5d 100644 --- a/harmony-rs/harmony_tui/src/lib.rs +++ b/harmony-rs/harmony_tui/src/lib.rs @@ -61,7 +61,7 @@ enum HarmonyTuiEvent { impl HarmonyTUI { pub fn new(maestro: Maestro) -> Self { let maestro = Arc::new(maestro); - let (handle, sender) = Self::start_channel(maestro.clone()); + let (_handle, sender) = Self::start_channel(maestro.clone()); let score = ScoreListWidget::new(Self::scores_list(&maestro), sender); HarmonyTUI { @@ -83,14 +83,17 @@ impl HarmonyTUI { HarmonyTuiEvent::LaunchScore(score_item) => { let maestro = maestro.clone(); - let interpretation_result = + let joinhandle_result = tokio::spawn(async move { maestro.interpret(score_item.0).await }) .await; - match interpretation_result { - Ok(success) => info!("Score execution successful {success:?}"), - Err(e) => { - error!("Score execution failed {:#?}", e); + match joinhandle_result { + Ok(interpretation_result) => match interpretation_result { + Ok(success) => info!("Score execution successful {success:?}"), + Err(error) => error!("Score failed {error:?}"), + }, + Err(joinhandle_failure) => { + error!("Score execution TASK FAILED! {:#?}", joinhandle_failure); } } }