From f8209c9162435383cc8a0f3e89d81d9edaae7e75 Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Sun, 15 Dec 2019 00:17:15 -0500 Subject: [PATCH] Update controls. --- README.md | 10 +++------ src/canvas.rs | 12 +++++------ src/data_conversion.rs | 26 +++++++++++------------ src/main.rs | 39 ++++++++++++++++++----------------- tests/arg_rate_tests.rs | 2 ++ tests/invalid_config_tests.rs | 1 + 6 files changed, 45 insertions(+), 45 deletions(-) create mode 100644 tests/invalid_config_tests.rs diff --git a/README.md b/README.md index ea9927af..c91b04e8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ You can install by cloning and using `cargo build --release`, or download the pr ### Windows -You can currently install by cloning and building yourself. You may need to install a font like [FreeMono](https://fonts2u.com/free-monospaced.font) and use a terminal like cmder for font support to work properly, unfortunately. +You can currently install by cloning and building yourself using `cargo build --release`. You may need to install a font like [FreeMono](https://fonts2u.com/free-monospaced.font) and use a terminal like cmder for font support to work properly, unfortunately. ### MacOS @@ -54,9 +54,9 @@ Note that all options and keybinds on GitHub may reflect the current development - `f` to freeze the screen from updating with new data. Press `f` again to unfreeze. Note that monitoring will still continue in the background. -- `Up/k`, `Down/j`, `Left/h`, `Right/l` to navigate between panels. +- `Ctrl+Up/k`, `Ctrl+Down/j`, `Ctrl+Left/h`, `Ctrl+Right/l` to navigate between panels. -- `Shift+Up` and `Shift+Down` scrolls through the list if the panel is a table (Temperature, Disks, Processes). +- `Up` and `Down` scrolls through the list if the panel is a table (Temperature, Disks, Processes). - `Esc` to close a dialog window. @@ -98,7 +98,3 @@ Note that all options and keybinds on GitHub may reflect the current development - [tokio](https://github.com/tokio-rs/tokio) - [tui-rs](https://github.com/fdehau/tui-rs) - [winapi](https://github.com/retep998/winapi-rs) - -## Why - -I was looking to try writing more things in Rust, and I love the gotop tool. And thus, this project was born. diff --git a/src/canvas.rs b/src/canvas.rs index 00e70d41..baffb2d2 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -55,13 +55,13 @@ pub fn draw_data(terminal: &mut Terminal, app_state: &mu .constraints([Constraint::Percentage(30), Constraint::Percentage(40), Constraint::Percentage(30)].as_ref()) .split(vertical_dialog_chunk[1]); - let text = [ + let help_text = [ Text::raw("\nGeneral Keybinds\n"), Text::raw("q, Ctrl-c to quit.\n"), Text::raw("Ctrl-r to reset all data.\n"), Text::raw("f to toggle freezing and unfreezing the display.\n"), - Text::raw("Up/k, Down/j, Left/h, Right/l to navigate between panels.\n"), - Text::raw("Shift+Up and Shift+Down scrolls through the list.\n"), + Text::raw("Ctrl+Up/k, Ctrl+Down/j, Ctrl+Left/h, Ctrl+Right/l to navigate between panels.\n"), + Text::raw("Up and Down scrolls through a list.\n"), Text::raw("Esc to close a dialog window (help or dd confirmation).\n"), Text::raw("? to get this help screen.\n"), Text::raw("\n Process Panel Keybinds\n"), @@ -72,7 +72,7 @@ pub fn draw_data(terminal: &mut Terminal, app_state: &mu Text::raw("n to sort by process name.\n"), ]; - Paragraph::new(text.iter()) + Paragraph::new(help_text.iter()) .block(Block::default().title("Help (Press Esc to close)").borders(Borders::ALL)) .style(Style::default().fg(Color::Gray)) .alignment(Alignment::Left) @@ -193,7 +193,7 @@ pub fn draw_data(terminal: &mut Terminal, app_state: &mu .labels(&["0%", "100%"]); let mem_name = "RAM:".to_string() - + &format!("{:3}%", (canvas_data.mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64)) + + &format!("{:3}%", (canvas_data.mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.floor() as u64)) + &format!( " {:.1}GB/{:.1}GB", canvas_data.mem_values.first().unwrap_or(&(0, 0)).0 as f64 / 1024.0, @@ -211,7 +211,7 @@ pub fn draw_data(terminal: &mut Terminal, app_state: &mu if let Some(last_canvas_result) = (&canvas_data.swap_data).last() { if last_canvas_result.1 >= 0.0 { swap_name = "SWP:".to_string() - + &format!("{:3}%", (canvas_data.swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64)) + + &format!("{:3}%", (canvas_data.swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.floor() as u64)) + &format!( " {:.1}GB/{:.1}GB", canvas_data.mem_values[1].0 as f64 / 1024.0, diff --git a/src/data_conversion.rs b/src/data_conversion.rs index 3417e04b..b94af4c4 100644 --- a/src/data_conversion.rs +++ b/src/data_conversion.rs @@ -41,19 +41,19 @@ pub fn update_disk_row(app_data: &data_collection::Data) -> Vec> { let read_bytes_per_sec = ((ele.read_bytes - prev.read_bytes) as f64 / time_difference) as u64; let write_bytes_per_sec = ((ele.write_bytes - prev.write_bytes) as f64 / time_difference) as u64; ( - if read_bytes_per_sec < 1024 { + if read_bytes_per_sec < 1000 { format!("{}B", read_bytes_per_sec) - } else if read_bytes_per_sec < 1024 * 1024 { - format!("{}KB", read_bytes_per_sec / 1024) + } else if read_bytes_per_sec < 1000 * 1000 { + format!("{}KB", read_bytes_per_sec / 1000) } else { - format!("{}MB", read_bytes_per_sec / 1024 / 1024) + format!("{}MB", read_bytes_per_sec / 1000 / 1000) }, - if write_bytes_per_sec < 1024 { + if write_bytes_per_sec < 1000 { format!("{}B", write_bytes_per_sec) - } else if write_bytes_per_sec < 1024 * 1024 { - format!("{}KB", write_bytes_per_sec / 1024) + } else if write_bytes_per_sec < 1000 * 1000 { + format!("{}KB", write_bytes_per_sec / 1000) } else { - format!("{}MB", write_bytes_per_sec / 1024 / 1024) + format!("{}MB", write_bytes_per_sec / 1000 / 1000) }, ) } else { @@ -72,15 +72,15 @@ pub fn update_disk_row(app_data: &data_collection::Data) -> Vec> { disk.name.to_string(), disk.mount_point.to_string(), format!("{:.0}%", disk.used_space as f64 / disk.total_space as f64 * 100_f64), - if disk.free_space < 1024 { + if disk.free_space < 1000 { disk.free_space.to_string() + "MB" } else { - (disk.free_space / 1024).to_string() + "GB" + (disk.free_space / 1000).to_string() + "GB" }, - if disk.total_space < 1024 { + if disk.total_space < 1000 { disk.total_space.to_string() + "MB" } else { - (disk.total_space / 1024).to_string() + "GB" + (disk.total_space / 1000).to_string() + "GB" }, io_activity.0, io_activity.1, @@ -104,7 +104,7 @@ pub fn update_process_row(app_data: &data_collection::Data) -> Vec> mem_usage } else if let Some(mem_usage_kb) = process.mem_usage_kb { if let Some(mem_data) = app_data.memory.last() { - (mem_usage_kb / 1024) as f64 / mem_data.mem_total_in_mb as f64 * 100_f64 + (mem_usage_kb / 1000) as f64 / mem_data.mem_total_in_mb as f64 * 100_f64 } else { 0_f64 } diff --git a/src/main.rs b/src/main.rs index 8a6ff033..ada8b05d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,19 +46,20 @@ enum ResetEvent { fn main() -> error::Result<()> { // Parse command line options let matches = clap_app!(app => - (name: crate_name!()) - (version: crate_version!()) - (author: crate_authors!()) - (about: crate_description!()) - (@arg AVG_CPU: -a --avgcpu "Enables showing the average CPU usage.") - (@arg DOT_MARKER: -m --dot_marker "Use a dot marker instead of the default braille marker. May be needed in things like Powershell.") - (@arg DEBUG: -d --debug "Enables debug mode.") - (@group TEMPERATURE_TYPE => - (@arg CELSIUS : -c --celsius "Sets the temperature type to Celsius. This is the default option.") - (@arg FAHRENHEIT : -f --fahrenheit "Sets the temperature type to Fahrenheit.") - (@arg KELVIN : -k --kelvin "Sets the temperature type to Kelvin.") - ) - (@arg RATE_MILLIS: -r --rate +takes_value "Sets a refresh rate in milliseconds; the minimum is 250ms, defaults to 1000ms. Smaller values may take more resources.") + (name: crate_name!()) + (version: crate_version!()) + (author: crate_authors!()) + (about: crate_description!()) + (@arg AVG_CPU: -a --avgcpu "Enables showing the average CPU usage.") + (@arg DOT_MARKER: -m --dot_marker "Use a dot marker instead of the default braille marker.") + (@arg DEBUG: -d --debug "Enables debug mode, which will output a log file.") + (@group TEMPERATURE_TYPE => + (@arg CELSIUS : -c --celsius "Sets the temperature type to Celsius. This is the default option.") + (@arg FAHRENHEIT : -f --fahrenheit "Sets the temperature type to Fahrenheit.") + (@arg KELVIN : -k --kelvin "Sets the temperature type to Kelvin.") + ) + (@arg RATE_MILLIS: -r --rate +takes_value "Sets a refresh rate in milliseconds; the minimum is 250ms, defaults to 1000ms. Smaller values may take more resources.") + //(@arg CONFIG_LOCATION: -co --config +takes_value "Sets the location of the config file. Expects a config file in the JSON format.") ) .get_matches(); @@ -213,18 +214,18 @@ fn main() -> error::Result<()> { Event::KeyInput(event) => { match event { KeyEvent::Ctrl('c') | KeyEvent::Char('q') => break, - KeyEvent::Char('h') | KeyEvent::Left => app.on_left(), - KeyEvent::Char('l') | KeyEvent::Right => app.on_right(), - KeyEvent::Char('k') | KeyEvent::Up => app.on_up(), - KeyEvent::Char('j') | KeyEvent::Down => app.on_down(), + KeyEvent::Char('h') | KeyEvent::CtrlLeft => app.on_left(), + KeyEvent::Char('l') | KeyEvent::CtrlRight => app.on_right(), + KeyEvent::Char('k') | KeyEvent::CtrlUp => app.on_up(), + KeyEvent::Char('j') | KeyEvent::CtrlDown => app.on_down(), KeyEvent::Ctrl('r') => { while rtx.send(ResetEvent::Reset).is_err() { debug!("Sent reset message."); } debug!("Resetting begins..."); } - KeyEvent::ShiftUp => app.decrement_position_count(), - KeyEvent::ShiftDown => app.increment_position_count(), + KeyEvent::Up => app.decrement_position_count(), + KeyEvent::Down => app.increment_position_count(), KeyEvent::Char(c) => app.on_key(c), //KeyEvent::Enter => app.on_enter(), KeyEvent::Esc => app.on_esc(), diff --git a/tests/arg_rate_tests.rs b/tests/arg_rate_tests.rs index 60c58297..6f71325a 100644 --- a/tests/arg_rate_tests.rs +++ b/tests/arg_rate_tests.rs @@ -2,6 +2,8 @@ use assert_cmd::prelude::*; use predicates::prelude::*; use std::process::Command; +// These tests are mostly here just to ensure that invalid results will be caught when passing arguments... + //======================RATES======================// #[test] diff --git a/tests/invalid_config_tests.rs b/tests/invalid_config_tests.rs new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/tests/invalid_config_tests.rs @@ -0,0 +1 @@ +