From d2bfc3db29579e04eb623c968ca211f9c5cfcdab Mon Sep 17 00:00:00 2001 From: PuQing Date: Sat, 28 Sep 2024 17:57:50 +0800 Subject: [PATCH] Update version to 0.1.2 in Cargo.toml and Cargo.lock --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/app.rs | 12 ++++++++++-- src/cli.rs | 10 +++++++++- src/components/dash.rs | 10 ++++++++-- src/main.rs | 2 +- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d12a4bb..6d36c20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2426,7 +2426,7 @@ dependencies = [ [[package]] name = "ttydash" -version = "0.1.1" +version = "0.1.2" dependencies = [ "anyhow", "better-panic", diff --git a/Cargo.toml b/Cargo.toml index 10af2c8..b0eef86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ttydash" -version = "0.1.1" +version = "0.1.2" edition = "2021" description = "A rust based tty plot" authors = ["PuQing "] diff --git a/src/app.rs b/src/app.rs index 7cc2da2..3a844d0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -75,7 +75,12 @@ pub struct App { } impl App { - pub fn new(tick_rate: f64, frame_rate: f64) -> Result { + pub fn new( + tick_rate: f64, + frame_rate: f64, + title: Option, + units: Option, + ) -> Result { let (action_tx, action_rx) = mpsc::unbounded_channel(); let mut keybindings = KeyBindings::new(); keybindings.bind_keys( @@ -96,7 +101,10 @@ impl App { Ok(Self { tick_rate, frame_rate, - components: vec![Box::new(Dash::new()), Box::new(FpsCounter::default())], + components: vec![ + Box::new(Dash::new(title, units)), + Box::new(FpsCounter::default()), + ], should_quit: false, should_suspend: false, last_tick_key_events: Vec::new(), diff --git a/src/cli.rs b/src/cli.rs index 3deda40..04533e5 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -4,12 +4,20 @@ use clap::Parser; #[command(author, version = version(), about)] pub struct Cli { /// Tick rate, i.e. number of ticks per second - #[arg(short, long, value_name = "FLOAT", default_value_t = 4.0)] + #[arg(long, value_name = "FLOAT", default_value_t = 4.0)] pub tick_rate: f64, /// Frame rate, i.e. number of frames per second #[arg(short, long, value_name = "FLOAT", default_value_t = 60.0)] pub frame_rate: f64, + + /// Chart title, will be shown at the top of the chart + #[arg(short, long, value_name = "STRING")] + pub title: Option, + + /// Chart unit, will be shown at the y-axis + #[arg(short, long, value_name = "STRING")] + pub unit: Option, } const VERSION_MESSAGE: &str = concat!( diff --git a/src/components/dash.rs b/src/components/dash.rs index 5e6f7b4..3b76fb1 100644 --- a/src/components/dash.rs +++ b/src/components/dash.rs @@ -39,13 +39,15 @@ impl Default for DashState { #[derive(Debug, Default, Clone)] pub struct Dash { + title: Option, + unit: Option, command_tx: Option>, state: Arc>, bar_set: bar::Set, } impl Dash { - pub fn new() -> Self { + pub fn new(title: Option, unit: Option) -> Self { let bar_set = bar::Set { full: "⣿", seven_eighths: "⣾", @@ -58,6 +60,8 @@ impl Dash { empty: "⠀", }; let instance = Self { + title, + unit, command_tx: None, state: Arc::new(RwLock::new(DashState::default())), bar_set, @@ -104,6 +108,8 @@ impl Component for Dash { } fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> { + let title = self.title.clone().unwrap_or_default(); + let width = area.width - 1; let state = self.state.read().unwrap(); let chart_state = &state.data; @@ -140,7 +146,7 @@ impl Component for Dash { .block( Block::default() .border_type(BorderType::Rounded) - .title(Line::from(state.unit.clone()).centered()) + .title(Line::from(title).centered()) .title_bottom(Line::from(span_vec)) .title_alignment(Alignment::Right) .borders(Borders::ALL), diff --git a/src/main.rs b/src/main.rs index 78f9cdf..647e34f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ async fn main() -> Result<()> { logging::init()?; let args = Cli::parse(); - let mut app = App::new(args.tick_rate, args.frame_rate)?; + let mut app = App::new(args.tick_rate, args.frame_rate, args.title, args.unit)?; app.run().await?; Ok(()) }