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:
parent
e5b4b5114e
commit
697c669d05
18
harmony-rs/examples/tui/Cargo.toml
Normal file
18
harmony-rs/examples/tui/Cargo.toml
Normal 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 }
|
||||||
19
harmony-rs/examples/tui/src/main.rs
Normal file
19
harmony-rs/examples/tui/src/main.rs
Normal 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();
|
||||||
|
}
|
||||||
@ -61,7 +61,7 @@ enum HarmonyTuiEvent {
|
|||||||
impl HarmonyTUI {
|
impl HarmonyTUI {
|
||||||
pub fn new(maestro: Maestro) -> Self {
|
pub fn new(maestro: Maestro) -> Self {
|
||||||
let maestro = Arc::new(maestro);
|
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);
|
let score = ScoreListWidget::new(Self::scores_list(&maestro), sender);
|
||||||
|
|
||||||
HarmonyTUI {
|
HarmonyTUI {
|
||||||
@ -83,14 +83,17 @@ impl HarmonyTUI {
|
|||||||
HarmonyTuiEvent::LaunchScore(score_item) => {
|
HarmonyTuiEvent::LaunchScore(score_item) => {
|
||||||
let maestro = maestro.clone();
|
let maestro = maestro.clone();
|
||||||
|
|
||||||
let interpretation_result =
|
let joinhandle_result =
|
||||||
tokio::spawn(async move { maestro.interpret(score_item.0).await })
|
tokio::spawn(async move { maestro.interpret(score_item.0).await })
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
match interpretation_result {
|
match joinhandle_result {
|
||||||
Ok(success) => info!("Score execution successful {success:?}"),
|
Ok(interpretation_result) => match interpretation_result {
|
||||||
Err(e) => {
|
Ok(success) => info!("Score execution successful {success:?}"),
|
||||||
error!("Score execution failed {:#?}", e);
|
Err(error) => error!("Score failed {error:?}"),
|
||||||
|
},
|
||||||
|
Err(joinhandle_failure) => {
|
||||||
|
error!("Score execution TASK FAILED! {:#?}", joinhandle_failure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user