From 0697e448025fdc4aaa8b2beee785b226ba5b8fcb Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Wed, 9 Oct 2019 22:34:09 -0400 Subject: [PATCH] Added freezing of updates. --- Cargo.toml | 2 +- README.md | 2 ++ TODO.md | 4 +--- src/app.rs | 8 ++++++-- src/canvas.rs | 9 +++++---- src/main.rs | 42 ++++++++++++++++++++++-------------------- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 38ef6168..6d3ac010 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ tokio = "0.2.0-alpha.4" winapi = "0.3.8" [dependencies.tui-temp-fork] -git = "https://github.com/ClementTsang/tui-rs" +#git = "https://github.com/ClementTsang/tui-rs" #path = "../tui-rs" version = "0.6.4" default-features = false diff --git a/README.md b/README.md index 417ca136..312dba5e 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ Currently, I'm unable to really dev or test on MacOS, so I'm not sure how well t - `q`, `Ctrl-C` to quit. +- `f` to freeze updating. Press `f` again to unfreeze. Note updating will still continue in the background. + - `Up/k`, `Down/j`, `Left/h`, `Right/l` to navigate between panels. - `Shift+Up` and `Shift+Down` scrolls through the list if the panel is a table (Temperature, Disks, Processes). diff --git a/TODO.md b/TODO.md index d2091f40..28b42f00 100644 --- a/TODO.md +++ b/TODO.md @@ -8,7 +8,7 @@ Note this will probably migrate to GitHub's native Issues; this was mostly for p - Scaling in and out (zoom), may need to show zoom levels -- More keybinds (jumping, scaling, help) +- More keybinds (jumping, scaling) - ~~Add custom error because it's really messy~~ Done, but need to implement across rest of app! @@ -16,8 +16,6 @@ Note this will probably migrate to GitHub's native Issues; this was mostly for p - Filtering in processes (that is, allow searching) -- Help screen - - Probably good to add a "are you sure" to dd-ing... ## Less important diff --git a/src/app.rs b/src/app.rs index 3c8aeb3b..752b0be9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -40,6 +40,7 @@ pub struct App { awaiting_second_d : bool, pub use_dot : bool, pub show_help : bool, + pub is_frozen : bool, } impl App { @@ -64,6 +65,7 @@ impl App { awaiting_second_d : false, use_dot, show_help : false, + is_frozen : false, } } @@ -83,14 +85,16 @@ impl App { 'd' => { if self.awaiting_second_d { self.awaiting_second_d = false; - self.kill_highlighted_process().unwrap_or(()); // TODO: Should this be handled? + self.kill_highlighted_process().unwrap_or(()); } else { self.awaiting_second_d = true; } } + 'f' => { + self.is_frozen = !self.is_frozen; + } 'c' => { - // TODO: This should depend on what tile you're on! match self.process_sorting_type { processes::ProcessSorting::CPU => self.process_sorting_reverse = !self.process_sorting_reverse, _ => { diff --git a/src/canvas.rs b/src/canvas.rs index c9e7b05b..eff9b755 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -61,6 +61,7 @@ pub fn draw_data(terminal : &mut Terminal, app_state : let text = [ Text::raw("\nGeneral Keybinds\n"), Text::raw("q, Ctrl-C to quit.\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("Esc to close a dialog window (help or dd confirmation).\n"), @@ -400,10 +401,10 @@ pub fn draw_data(terminal : &mut Terminal, app_state : { use app::data_collection::processes::ProcessSorting; - let mut pid = "PID".to_string(); - let mut name = "Name".to_string(); - let mut cpu = "CPU%".to_string(); - let mut mem = "Mem%".to_string(); + let mut pid = "PID (p)".to_string(); + let mut name = "Name (n)".to_string(); + let mut cpu = "CPU% (c)".to_string(); + let mut mem = "Mem% (m)".to_string(); let direction_val = if app_state.process_sorting_reverse { " ⯆".to_string() diff --git a/src/main.rs b/src/main.rs index 6a6651d3..bb57c1d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -226,28 +226,30 @@ fn main() -> error::Result<()> { } Event::Update(data) => { // debug!("Update event fired!"); - app.data = *data; - data_collection::processes::sort_processes( - &mut app.data.list_of_processes, - &app.process_sorting_type, - app.process_sorting_reverse, - ); + if !app.is_frozen { + app.data = *data; + data_collection::processes::sort_processes( + &mut app.data.list_of_processes, + &app.process_sorting_type, + app.process_sorting_reverse, + ); - // Convert all data into tui components - let network_data = update_network_data_points(&app.data); - canvas_data.network_data_rx = network_data.rx; - canvas_data.network_data_tx = network_data.tx; - canvas_data.rx_display = network_data.rx_display; - canvas_data.tx_display = network_data.tx_display; - canvas_data.disk_data = update_disk_row(&app.data); - canvas_data.temp_sensor_data = update_temp_row(&app.data, &app.temperature_type); - canvas_data.process_data = update_process_row(&app.data); - canvas_data.mem_data = update_mem_data_points(&app.data); - canvas_data.mem_values = update_mem_data_values(&app.data); - canvas_data.swap_data = update_swap_data_points(&app.data); - canvas_data.cpu_data = update_cpu_data_points(app.show_average_cpu, &app.data); + // Convert all data into tui components + let network_data = update_network_data_points(&app.data); + canvas_data.network_data_rx = network_data.rx; + canvas_data.network_data_tx = network_data.tx; + canvas_data.rx_display = network_data.rx_display; + canvas_data.tx_display = network_data.tx_display; + canvas_data.disk_data = update_disk_row(&app.data); + canvas_data.temp_sensor_data = update_temp_row(&app.data, &app.temperature_type); + canvas_data.process_data = update_process_row(&app.data); + canvas_data.mem_data = update_mem_data_points(&app.data); + canvas_data.mem_values = update_mem_data_values(&app.data); + canvas_data.swap_data = update_swap_data_points(&app.data); + canvas_data.cpu_data = update_cpu_data_points(app.show_average_cpu, &app.data); - debug!("Update event complete."); + debug!("Update event complete."); + } } } }