diff options
author | ClementTsang <clementjhtsang@gmail.com> | 2020-01-08 22:54:14 -0500 |
---|---|---|
committer | ClementTsang <clementjhtsang@gmail.com> | 2020-01-08 22:54:14 -0500 |
commit | 13180c72d40947c461197c543851b6eadcfbb908 (patch) | |
tree | 628f8b6c043ca9d8f6c989f81dae6040331b4950 /src | |
parent | c171cd0e0b8d37c71a666e838b52868feaae6e62 (diff) |
Add flag to enable by default, documentation
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 8 | ||||
-rw-r--r-- | src/canvas.rs | 3 | ||||
-rw-r--r-- | src/main.rs | 39 |
3 files changed, 39 insertions, 11 deletions
@@ -124,6 +124,14 @@ impl App { } } + pub fn on_tab(&mut self) { + match self.current_application_position { + ApplicationPosition::Process => self.toggle_grouping(), + ApplicationPosition::Disk => {} + _ => {} + } + } + pub fn is_grouped(&self) -> bool { self.enable_grouping } diff --git a/src/canvas.rs b/src/canvas.rs index 90ab09b9..96a6b824 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -19,7 +19,7 @@ const HIGHLIGHTED_BORDER_STYLE_COLOUR: Color = Color::LightBlue; const GOLDEN_RATIO: f32 = 0.618_034; // Approx, good enough for use (also Clippy gets mad if it's too long) lazy_static! { - static ref HELP_TEXT: [Text<'static>; 14] = [ + static ref HELP_TEXT: [Text<'static>; 15] = [ Text::raw("\nGeneral Keybindings\n"), Text::raw("q, Ctrl-c to quit.\n"), Text::raw("Ctrl-r to reset all data.\n"), @@ -36,6 +36,7 @@ lazy_static! { Text::raw("m to sort by memory usage.\n"), Text::raw("p to sort by PID.\n"), Text::raw("n to sort by process name.\n"), + Text::raw("`Tab` to group together processes with the same name.\n") ]; static ref COLOUR_LIST: Vec<Color> = gen_n_colours(constants::NUM_COLOURS); static ref CANVAS_BORDER_STYLE: Style = Style::default().fg(BORDER_STYLE_COLOUR); diff --git a/src/main.rs b/src/main.rs index 8cdc4e50..1ff5ba57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,6 +72,7 @@ fn main() -> error::Result<()> { (@arg USE_CURR_USAGE: -u --current_usage "Within Linux, sets a process' CPU usage to be based on the total current CPU usage, rather than assuming 100% usage.") //(@arg CONFIG_LOCATION: -co --config +takes_value "Sets the location of the config file. Expects a config file in the JSON format.") (@arg BASIC_MODE: -b --basic "Sets bottom to basic mode, not showing graphs and only showing basic tables.") + (@arg GROUP_PROCESSES: -g --group "Groups processes with the same name together on launch.") ) .get_matches(); @@ -123,6 +124,11 @@ fn main() -> error::Result<()> { use_current_cpu_total, ); + // Enable grouping immediately if set. + if matches.is_present("GROUP_PROCESSES") { + app.toggle_grouping(); + } + // Set up up tui and crossterm let mut stdout = stdout(); enable_raw_mode()?; @@ -219,7 +225,7 @@ fn main() -> error::Result<()> { KeyCode::Char(uncaught_char) => app.on_char_key(uncaught_char), KeyCode::Esc => app.reset(), KeyCode::Enter => app.on_enter(), - KeyCode::Tab => app.toggle_grouping(), + KeyCode::Tab => app.on_tab(), _ => {} } } else { @@ -299,6 +305,15 @@ fn main() -> error::Result<()> { } } } + + // Quick fix for tab updating the table headers + if let data_collection::processes::ProcessSorting::PID = &app.process_sorting_type { + if app.is_grouped() { + app.process_sorting_type = data_collection::processes::ProcessSorting::CPU; // Go back to default, negate PID for group + app.process_sorting_reverse = true; + } + } + // Draw! if let Err(err) = canvas::draw_data(&mut terminal, &mut app) { cleanup(&mut terminal)?; @@ -361,15 +376,19 @@ fn handle_process_sorting(app: &mut app::App) { ); if let Some(grouped_list_of_processes) = &mut app.data.grouped_list_of_processes { - data_collection::processes::sort_processes( - grouped_list_of_processes, - if let data_collection::processes::ProcessSorting::PID = &app.process_sorting_type { - &data_collection::processes::ProcessSorting::CPU // Go back to default, negate PID for group - } else { - &app.process_sorting_type - }, - app.process_sorting_reverse, - ); + if let data_collection::processes::ProcessSorting::PID = &app.process_sorting_type { + data_collection::processes::sort_processes( + grouped_list_of_processes, + &data_collection::processes::ProcessSorting::CPU, // Go back to default, negate PID for group + true, + ); + } else { + data_collection::processes::sort_processes( + grouped_list_of_processes, + &app.process_sorting_type, + app.process_sorting_reverse, + ); + } } data_collection::processes::sort_processes( |