From 45668638e1339ec2a9dd26ac9c5d15ec8f3cbf3c Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Wed, 23 Apr 2025 11:16:33 -0400 Subject: [PATCH] feat: TUI does not require Topology to implement Debug anymore --- examples/lamp/src/main.rs | 2 +- examples/tui/src/main.rs | 1 - harmony_tui/src/lib.rs | 4 ++-- harmony_tui/src/widget/score.rs | 16 ++++++++++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/lamp/src/main.rs b/examples/lamp/src/main.rs index 0887d04..3075e31 100644 --- a/examples/lamp/src/main.rs +++ b/examples/lamp/src/main.rs @@ -17,7 +17,7 @@ async fn main() { }, }; - let maestro = Maestro::::load_from_env(); + let mut maestro = Maestro::::load_from_env(); maestro.register_all(vec![Box::new(lamp_stack)]); harmony_tui::init(maestro).await.unwrap(); } diff --git a/examples/tui/src/main.rs b/examples/tui/src/main.rs index 5ed607a..72f9aab 100644 --- a/examples/tui/src/main.rs +++ b/examples/tui/src/main.rs @@ -22,7 +22,6 @@ async fn main() { let topology = HAClusterTopology::autoload(); let mut maestro = Maestro::new(inventory, topology); - maestro.register_all(vec![ Box::new(SuccessScore {}), Box::new(ErrorScore {}), diff --git a/harmony_tui/src/lib.rs b/harmony_tui/src/lib.rs index 908b057..180d608 100644 --- a/harmony_tui/src/lib.rs +++ b/harmony_tui/src/lib.rs @@ -67,10 +67,10 @@ enum HarmonyTuiEvent { LaunchScore(Box>), } -impl std::fmt::Display for HarmonyTuiEvent { +impl std::fmt::Display for HarmonyTuiEvent { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let output = match self { - HarmonyTuiEvent::LaunchScore(score) => format!("LaunchScore({})",score.name()), + HarmonyTuiEvent::LaunchScore(score) => format!("LaunchScore({})", score.name()), }; f.write_str(&output) diff --git a/harmony_tui/src/widget/score.rs b/harmony_tui/src/widget/score.rs index 3acb5c2..57a93fe 100644 --- a/harmony_tui/src/widget/score.rs +++ b/harmony_tui/src/widget/score.rs @@ -19,13 +19,21 @@ enum ExecutionState { CANCELED, } -#[derive(Debug)] struct Execution { state: ExecutionState, score: Box>, } -#[derive(Debug)] +impl std::fmt::Display for Execution { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!( + "Execution of {} status {:?}", + self.score.name(), + self.state + )) + } +} + pub(crate) struct ScoreListWidget { list_state: Arc>, scores: Vec>>, @@ -34,7 +42,7 @@ pub(crate) struct ScoreListWidget { sender: mpsc::Sender>, } -impl ScoreListWidget { +impl ScoreListWidget { pub(crate) fn new( scores: Vec>>, sender: mpsc::Sender>, @@ -99,7 +107,7 @@ impl ScoreListWidget { match confirm { true => { execution.state = ExecutionState::RUNNING; - info!("Launch execution {:?}", execution); + info!("Launch execution {execution}"); self.sender .send(HarmonyTuiEvent::LaunchScore(execution.score.clone_box())) .await