Skip to content

Commit

Permalink
Update version to 0.1.2 in Cargo.toml and Cargo.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
AndPuQing committed Sep 28, 2024
1 parent d5a3e9b commit d2bfc3d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand Down
12 changes: 10 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ pub struct App {
}

impl App {
pub fn new(tick_rate: f64, frame_rate: f64) -> Result<Self> {
pub fn new(
tick_rate: f64,
frame_rate: f64,
title: Option<String>,
units: Option<String>,
) -> Result<Self> {
let (action_tx, action_rx) = mpsc::unbounded_channel();
let mut keybindings = KeyBindings::new();
keybindings.bind_keys(
Expand All @@ -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(),
Expand Down
10 changes: 9 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// Chart unit, will be shown at the y-axis
#[arg(short, long, value_name = "STRING")]
pub unit: Option<String>,
}

const VERSION_MESSAGE: &str = concat!(
Expand Down
10 changes: 8 additions & 2 deletions src/components/dash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ impl Default for DashState {

#[derive(Debug, Default, Clone)]
pub struct Dash {
title: Option<String>,
unit: Option<String>,

Check warning on line 43 in src/components/dash.rs

View workflow job for this annotation

GitHub Actions / Publishing for macos-latest

field `unit` is never read

Check warning on line 43 in src/components/dash.rs

View workflow job for this annotation

GitHub Actions / Publishing for macos-latest

field `unit` is never read

Check warning on line 43 in src/components/dash.rs

View workflow job for this annotation

GitHub Actions / Publishing for ubuntu-latest

field `unit` is never read

Check warning on line 43 in src/components/dash.rs

View workflow job for this annotation

GitHub Actions / Publishing for ubuntu-latest

field `unit` is never read

Check warning on line 43 in src/components/dash.rs

View workflow job for this annotation

GitHub Actions / Publishing for ubuntu-latest

field `unit` is never read

Check warning on line 43 in src/components/dash.rs

View workflow job for this annotation

GitHub Actions / Publishing for windows-latest

field `unit` is never read
command_tx: Option<UnboundedSender<Action>>,
state: Arc<RwLock<DashState>>,
bar_set: bar::Set,
}

impl Dash {
pub fn new() -> Self {
pub fn new(title: Option<String>, unit: Option<String>) -> Self {
let bar_set = bar::Set {
full: "⣿",
seven_eighths: "⣾",
Expand All @@ -58,6 +60,8 @@ impl Dash {
empty: "⠀",
};
let instance = Self {
title,
unit,
command_tx: None,
state: Arc::new(RwLock::new(DashState::default())),
bar_set,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit d2bfc3d

Please sign in to comment.