diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 95 |
1 files changed, 68 insertions, 27 deletions
diff --git a/src/main.rs b/src/main.rs index 29c7630e..b3624046 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ use tui::{backend::CrosstermBackend, Terminal}; use app::{ data_harvester::{self, processes::ProcessSorting}, - layout_manager::UsedWidgets, + layout_manager::{UsedWidgets, WidgetDirection}, App, }; use constants::*; @@ -286,15 +286,10 @@ fn handle_key_event_or_break( KeyCode::Tab => app.on_tab(), KeyCode::Backspace => app.on_backspace(), KeyCode::Delete => app.on_delete(), - KeyCode::F(1) => { - app.toggle_ignore_case(); - } - KeyCode::F(2) => { - app.toggle_search_whole_word(); - } - KeyCode::F(3) => { - app.toggle_search_regex(); - } + KeyCode::F(1) => app.toggle_ignore_case(), + KeyCode::F(2) => app.toggle_search_whole_word(), + KeyCode::F(3) => app.toggle_search_regex(), + KeyCode::F(6) => app.toggle_sort(), _ => {} } } else { @@ -315,10 +310,10 @@ fn handle_key_event_or_break( match event.code { KeyCode::Char('f') => app.on_slash(), - KeyCode::Left => app.move_widget_selection_left(), - KeyCode::Right => app.move_widget_selection_right(), - KeyCode::Up => app.move_widget_selection_up(), - KeyCode::Down => app.move_widget_selection_down(), + KeyCode::Left => app.move_widget_selection(&WidgetDirection::Left), + KeyCode::Right => app.move_widget_selection(&WidgetDirection::Right), + KeyCode::Up => app.move_widget_selection(&WidgetDirection::Up), + KeyCode::Down => app.move_widget_selection(&WidgetDirection::Down), KeyCode::Char('r') => { if reset_sender.send(ResetEvent::Reset).is_ok() { app.reset(); @@ -338,10 +333,10 @@ fn handle_key_event_or_break( } } else if let KeyModifiers::SHIFT = event.modifiers { match event.code { - KeyCode::Left => app.move_widget_selection_left(), - KeyCode::Right => app.move_widget_selection_right(), - KeyCode::Up => app.move_widget_selection_up(), - KeyCode::Down => app.move_widget_selection_down(), + KeyCode::Left => app.move_widget_selection(&WidgetDirection::Left), + KeyCode::Right => app.move_widget_selection(&WidgetDirection::Right), + KeyCode::Up => app.move_widget_selection(&WidgetDirection::Up), + KeyCode::Down => app.move_widget_selection(&WidgetDirection::Down), KeyCode::Char(caught_char) => app.on_char_key(caught_char), _ => {} } @@ -607,7 +602,7 @@ fn update_final_process_list(app: &mut App, widget_id: u64) { } else { ProcessGroupingType::Ungrouped }, - if proc_widget_state.is_using_full_path { + if proc_widget_state.is_using_command { ProcessNamingType::Path } else { ProcessNamingType::Name @@ -636,12 +631,12 @@ fn update_final_process_list(app: &mut App, widget_id: u64) { // Quick fix for tab updating the table headers if let Some(proc_widget_state) = app.proc_state.get_mut_widget_state(widget_id) { - if let data_harvester::processes::ProcessSorting::PID = + if let data_harvester::processes::ProcessSorting::Pid = proc_widget_state.process_sorting_type { if proc_widget_state.is_grouped { proc_widget_state.process_sorting_type = - data_harvester::processes::ProcessSorting::CPU; // Go back to default, negate PID for group + data_harvester::processes::ProcessSorting::CpuPercent; // Go back to default, negate PID for group proc_widget_state.process_sorting_reverse = true; } } @@ -653,7 +648,7 @@ fn update_final_process_list(app: &mut App, widget_id: u64) { proc_widget_state.scroll_state.current_scroll_position = resulting_processes.len().saturating_sub(1); proc_widget_state.scroll_state.previous_scroll_position = 0; - proc_widget_state.scroll_state.scroll_direction = app::ScrollDirection::DOWN; + proc_widget_state.scroll_state.scroll_direction = app::ScrollDirection::Down; } app.canvas_data @@ -670,7 +665,7 @@ fn sort_process_data( }); match proc_widget_state.process_sorting_type { - ProcessSorting::CPU => { + ProcessSorting::CpuPercent => { to_sort_vec.sort_by(|a, b| { utils::gen_util::get_ordering( a.cpu_usage, @@ -679,7 +674,10 @@ fn sort_process_data( ) }); } - ProcessSorting::MEM => { + ProcessSorting::Mem => { + // TODO: Do when I do mem values in processes + } + ProcessSorting::MemPercent => { to_sort_vec.sort_by(|a, b| { utils::gen_util::get_ordering( a.mem_usage, @@ -688,8 +686,8 @@ fn sort_process_data( ) }); } - ProcessSorting::IDENTIFIER => { - // Don't repeat if false... + ProcessSorting::ProcessName | ProcessSorting::Command => { + // Don't repeat if false... it sorts by name by default anyways. if proc_widget_state.process_sorting_reverse { to_sort_vec.sort_by(|a, b| { utils::gen_util::get_ordering( @@ -700,7 +698,7 @@ fn sort_process_data( }) } } - ProcessSorting::PID => { + ProcessSorting::Pid => { if !proc_widget_state.is_grouped { to_sort_vec.sort_by(|a, b| { utils::gen_util::get_ordering( @@ -711,6 +709,49 @@ fn sort_process_data( }); } } + ProcessSorting::ReadPerSecond => { + to_sort_vec.sort_by(|a, b| { + utils::gen_util::get_ordering( + a.rps_f64, + b.rps_f64, + proc_widget_state.process_sorting_reverse, + ) + }); + } + ProcessSorting::WritePerSecond => { + to_sort_vec.sort_by(|a, b| { + utils::gen_util::get_ordering( + a.wps_f64, + b.wps_f64, + proc_widget_state.process_sorting_reverse, + ) + }); + } + ProcessSorting::TotalRead => { + to_sort_vec.sort_by(|a, b| { + utils::gen_util::get_ordering( + a.tr_f64, + b.tr_f64, + proc_widget_state.process_sorting_reverse, + ) + }); + } + ProcessSorting::TotalWrite => { + to_sort_vec.sort_by(|a, b| { + utils::gen_util::get_ordering( + a.tw_f64, + b.tw_f64, + proc_widget_state.process_sorting_reverse, + ) + }); + } + ProcessSorting::State => to_sort_vec.sort_by(|a, b| { + utils::gen_util::get_ordering( + &a.process_state.to_lowercase(), + &b.process_state.to_lowercase(), + proc_widget_state.process_sorting_reverse, + ) + }), } } |