Update controls.

This commit is contained in:
ClementTsang 2019-12-15 00:17:15 -05:00
parent 7592fec1d1
commit f8209c9162
6 changed files with 45 additions and 45 deletions

View file

@ -14,7 +14,7 @@ You can install by cloning and using `cargo build --release`, or download the pr
### Windows ### 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 ### 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. - `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. - `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) - [tokio](https://github.com/tokio-rs/tokio)
- [tui-rs](https://github.com/fdehau/tui-rs) - [tui-rs](https://github.com/fdehau/tui-rs)
- [winapi](https://github.com/retep998/winapi-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.

View file

@ -55,13 +55,13 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
.constraints([Constraint::Percentage(30), Constraint::Percentage(40), Constraint::Percentage(30)].as_ref()) .constraints([Constraint::Percentage(30), Constraint::Percentage(40), Constraint::Percentage(30)].as_ref())
.split(vertical_dialog_chunk[1]); .split(vertical_dialog_chunk[1]);
let text = [ let help_text = [
Text::raw("\nGeneral Keybinds\n"), Text::raw("\nGeneral Keybinds\n"),
Text::raw("q, Ctrl-c to quit.\n"), Text::raw("q, Ctrl-c to quit.\n"),
Text::raw("Ctrl-r to reset all data.\n"), Text::raw("Ctrl-r to reset all data.\n"),
Text::raw("f to toggle freezing and unfreezing the display.\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("Ctrl+Up/k, Ctrl+Down/j, Ctrl+Left/h, Ctrl+Right/l to navigate between panels.\n"),
Text::raw("Shift+Up and Shift+Down scrolls through the list.\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("Esc to close a dialog window (help or dd confirmation).\n"),
Text::raw("? to get this help screen.\n"), Text::raw("? to get this help screen.\n"),
Text::raw("\n Process Panel Keybinds\n"), Text::raw("\n Process Panel Keybinds\n"),
@ -72,7 +72,7 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
Text::raw("n to sort by process name.\n"), 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)) .block(Block::default().title("Help (Press Esc to close)").borders(Borders::ALL))
.style(Style::default().fg(Color::Gray)) .style(Style::default().fg(Color::Gray))
.alignment(Alignment::Left) .alignment(Alignment::Left)
@ -193,7 +193,7 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
.labels(&["0%", "100%"]); .labels(&["0%", "100%"]);
let mem_name = "RAM:".to_string() 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!( + &format!(
" {:.1}GB/{:.1}GB", " {:.1}GB/{:.1}GB",
canvas_data.mem_values.first().unwrap_or(&(0, 0)).0 as f64 / 1024.0, canvas_data.mem_values.first().unwrap_or(&(0, 0)).0 as f64 / 1024.0,
@ -211,7 +211,7 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
if let Some(last_canvas_result) = (&canvas_data.swap_data).last() { if let Some(last_canvas_result) = (&canvas_data.swap_data).last() {
if last_canvas_result.1 >= 0.0 { if last_canvas_result.1 >= 0.0 {
swap_name = "SWP:".to_string() 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!( + &format!(
" {:.1}GB/{:.1}GB", " {:.1}GB/{:.1}GB",
canvas_data.mem_values[1].0 as f64 / 1024.0, canvas_data.mem_values[1].0 as f64 / 1024.0,

View file

@ -41,19 +41,19 @@ pub fn update_disk_row(app_data: &data_collection::Data) -> Vec<Vec<String>> {
let read_bytes_per_sec = ((ele.read_bytes - prev.read_bytes) as f64 / time_difference) as u64; 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; 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) format!("{}B", read_bytes_per_sec)
} else if read_bytes_per_sec < 1024 * 1024 { } else if read_bytes_per_sec < 1000 * 1000 {
format!("{}KB", read_bytes_per_sec / 1024) format!("{}KB", read_bytes_per_sec / 1000)
} else { } 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) format!("{}B", write_bytes_per_sec)
} else if write_bytes_per_sec < 1024 * 1024 { } else if write_bytes_per_sec < 1000 * 1000 {
format!("{}KB", write_bytes_per_sec / 1024) format!("{}KB", write_bytes_per_sec / 1000)
} else { } else {
format!("{}MB", write_bytes_per_sec / 1024 / 1024) format!("{}MB", write_bytes_per_sec / 1000 / 1000)
}, },
) )
} else { } else {
@ -72,15 +72,15 @@ pub fn update_disk_row(app_data: &data_collection::Data) -> Vec<Vec<String>> {
disk.name.to_string(), disk.name.to_string(),
disk.mount_point.to_string(), disk.mount_point.to_string(),
format!("{:.0}%", disk.used_space as f64 / disk.total_space as f64 * 100_f64), 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" disk.free_space.to_string() + "MB"
} else { } 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" disk.total_space.to_string() + "MB"
} else { } else {
(disk.total_space / 1024).to_string() + "GB" (disk.total_space / 1000).to_string() + "GB"
}, },
io_activity.0, io_activity.0,
io_activity.1, io_activity.1,
@ -104,7 +104,7 @@ pub fn update_process_row(app_data: &data_collection::Data) -> Vec<Vec<String>>
mem_usage mem_usage
} else if let Some(mem_usage_kb) = process.mem_usage_kb { } else if let Some(mem_usage_kb) = process.mem_usage_kb {
if let Some(mem_data) = app_data.memory.last() { 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 { } else {
0_f64 0_f64
} }

View file

@ -46,19 +46,20 @@ enum ResetEvent {
fn main() -> error::Result<()> { fn main() -> error::Result<()> {
// Parse command line options // Parse command line options
let matches = clap_app!(app => let matches = clap_app!(app =>
(name: crate_name!()) (name: crate_name!())
(version: crate_version!()) (version: crate_version!())
(author: crate_authors!()) (author: crate_authors!())
(about: crate_description!()) (about: crate_description!())
(@arg AVG_CPU: -a --avgcpu "Enables showing the average CPU usage.") (@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 DOT_MARKER: -m --dot_marker "Use a dot marker instead of the default braille marker.")
(@arg DEBUG: -d --debug "Enables debug mode.") (@arg DEBUG: -d --debug "Enables debug mode, which will output a log file.")
(@group TEMPERATURE_TYPE => (@group TEMPERATURE_TYPE =>
(@arg CELSIUS : -c --celsius "Sets the temperature type to Celsius. This is the default option.") (@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 FAHRENHEIT : -f --fahrenheit "Sets the temperature type to Fahrenheit.")
(@arg KELVIN : -k --kelvin "Sets the temperature type to Kelvin.") (@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 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(); .get_matches();
@ -213,18 +214,18 @@ fn main() -> error::Result<()> {
Event::KeyInput(event) => { Event::KeyInput(event) => {
match event { match event {
KeyEvent::Ctrl('c') | KeyEvent::Char('q') => break, KeyEvent::Ctrl('c') | KeyEvent::Char('q') => break,
KeyEvent::Char('h') | KeyEvent::Left => app.on_left(), KeyEvent::Char('h') | KeyEvent::CtrlLeft => app.on_left(),
KeyEvent::Char('l') | KeyEvent::Right => app.on_right(), KeyEvent::Char('l') | KeyEvent::CtrlRight => app.on_right(),
KeyEvent::Char('k') | KeyEvent::Up => app.on_up(), KeyEvent::Char('k') | KeyEvent::CtrlUp => app.on_up(),
KeyEvent::Char('j') | KeyEvent::Down => app.on_down(), KeyEvent::Char('j') | KeyEvent::CtrlDown => app.on_down(),
KeyEvent::Ctrl('r') => { KeyEvent::Ctrl('r') => {
while rtx.send(ResetEvent::Reset).is_err() { while rtx.send(ResetEvent::Reset).is_err() {
debug!("Sent reset message."); debug!("Sent reset message.");
} }
debug!("Resetting begins..."); debug!("Resetting begins...");
} }
KeyEvent::ShiftUp => app.decrement_position_count(), KeyEvent::Up => app.decrement_position_count(),
KeyEvent::ShiftDown => app.increment_position_count(), KeyEvent::Down => app.increment_position_count(),
KeyEvent::Char(c) => app.on_key(c), KeyEvent::Char(c) => app.on_key(c),
//KeyEvent::Enter => app.on_enter(), //KeyEvent::Enter => app.on_enter(),
KeyEvent::Esc => app.on_esc(), KeyEvent::Esc => app.on_esc(),

View file

@ -2,6 +2,8 @@ use assert_cmd::prelude::*;
use predicates::prelude::*; use predicates::prelude::*;
use std::process::Command; use std::process::Command;
// These tests are mostly here just to ensure that invalid results will be caught when passing arguments...
//======================RATES======================// //======================RATES======================//
#[test] #[test]

View file

@ -0,0 +1 @@