feat(examples/tui): add TUI example with harmony integration

- Create `Cargo.toml` for the new TUI example under `examples/tui`
- Implement basic `main.rs` that initializes Maestro and launches the TUI
- Update `harmony_tui/src/lib.rs` to handle async score execution gracefully
This commit is contained in:
Jean-Gabriel Gill-Couture 2025-02-04 15:43:05 -05:00
parent e5b4b5114e
commit 697c669d05
3 changed files with 46 additions and 6 deletions

View File

@ -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 }

View File

@ -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();
}

View File

@ -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);
}
}
}