diff options
Diffstat (limited to 'src/app/widgets/bottom_widgets')
-rw-r--r-- | src/app/widgets/bottom_widgets/basic_mem.rs | 4 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/basic_net.rs | 1 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/cpu.rs | 150 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/mem.rs | 4 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/net.rs | 2 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/process.rs | 83 |
6 files changed, 180 insertions, 64 deletions
diff --git a/src/app/widgets/bottom_widgets/basic_mem.rs b/src/app/widgets/bottom_widgets/basic_mem.rs index 2f33183f..d70d0e04 100644 --- a/src/app/widgets/bottom_widgets/basic_mem.rs +++ b/src/app/widgets/bottom_widgets/basic_mem.rs @@ -129,7 +129,7 @@ impl Widget for BasicMem { // TODO: [Data update optimization] Probably should just make another function altogether for basic mode. self.mem_data = if let (Some(data), Some((_, fraction))) = ( - convert_mem_data_points(data_collection, false).last(), + convert_mem_data_points(data_collection).last(), memory_labels, ) { ( @@ -141,7 +141,7 @@ impl Widget for BasicMem { (0.0, "0.0B/0.0B".to_string(), "0%".to_string()) }; self.swap_data = if let (Some(data), Some((_, fraction))) = ( - convert_swap_data_points(data_collection, false).last(), + convert_swap_data_points(data_collection).last(), swap_labels, ) { Some(( diff --git a/src/app/widgets/bottom_widgets/basic_net.rs b/src/app/widgets/bottom_widgets/basic_net.rs index bdb15554..a739fd25 100644 --- a/src/app/widgets/bottom_widgets/basic_net.rs +++ b/src/app/widgets/bottom_widgets/basic_net.rs @@ -109,7 +109,6 @@ impl Widget for BasicNet { fn update_data(&mut self, data_collection: &DataCollection) { let network_data = convert_network_data_points( data_collection, - false, // TODO: I think the is_frozen here is also useless; see mem and cpu true, &AxisScaling::Linear, &self.unit_type, diff --git a/src/app/widgets/bottom_widgets/cpu.rs b/src/app/widgets/bottom_widgets/cpu.rs index 0b5cbae2..9397a7e1 100644 --- a/src/app/widgets/bottom_widgets/cpu.rs +++ b/src/app/widgets/bottom_widgets/cpu.rs @@ -9,7 +9,9 @@ use tui::{ use crate::{ app::{ - event::WidgetEventResult, text_table::SimpleColumn, time_graph::TimeGraphData, + event::{SelectionAction, WidgetEventResult}, + text_table::SimpleColumn, + time_graph::TimeGraphData, AppConfigFields, AppScrollWidgetState, CanvasTableWidthState, Component, DataCollection, TextTable, TimeGraph, Widget, }, @@ -47,7 +49,6 @@ impl CpuState { enum CpuGraphSelection { Graph, Legend, - None, } /// Whether the [`CpuGraph`]'s legend is placed on the left or right. @@ -95,7 +96,7 @@ impl CpuGraph { legend_position, showing_avg, bounds: Rect::default(), - selected: CpuGraphSelection::None, + selected: CpuGraphSelection::Graph, display_data: Default::default(), load_avg_data: [0.0; 3], width: LayoutRule::default(), @@ -121,7 +122,6 @@ impl Component for CpuGraph { match self.selected { CpuGraphSelection::Graph => self.graph.handle_key_event(event), CpuGraphSelection::Legend => self.legend.handle_key_event(event), - CpuGraphSelection::None => WidgetEventResult::NoRedraw, } } @@ -190,6 +190,55 @@ impl Widget for CpuGraph { CpuGraphLegendPosition::Right => (split_area[0], split_area[1]), }; + let legend_block = self + .block() + .selected(selected && matches!(&self.selected, CpuGraphSelection::Legend)) + .expanded(expanded) + .hide_title(true); + + let legend_data = self + .display_data + .iter() + .enumerate() + .map(|(cpu_index, core_data)| { + let style = Some(if cpu_index == 0 { + painter.colours.all_colour_style + } else if self.showing_avg && cpu_index == 1 { + painter.colours.avg_colour_style + } else { + let cpu_style_index = if self.showing_avg { + // No underflow should occur, as if cpu_index was + // 1 and avg is showing, it's caught by the above case! + cpu_index - 2 + } else { + cpu_index - 1 + }; + painter.colours.cpu_colour_styles + [cpu_style_index % painter.colours.cpu_colour_styles.len()] + }); + + vec![ + ( + core_data.cpu_name.clone().into(), + Some(core_data.short_cpu_name.clone().into()), + style, + ), + (core_data.legend_value.clone().into(), None, style), + ] + }) + .collect::<Vec<_>>(); + + // TODO: You MUST draw the table first, otherwise the index may mismatch after a reset. This is a bad gotcha - we should look into auto-updating the table's length! + self.legend.draw_tui_table( + painter, + f, + &legend_data, + legend_block, + legend_block_area, + true, + false, + ); + const Y_BOUNDS: [f64; 2] = [0.0, 100.5]; let y_bound_labels: [Cow<'static, str>; 2] = ["0%".into(), "100%".into()]; @@ -243,59 +292,10 @@ impl Widget for CpuGraph { graph_block, graph_block_area, ); - - let legend_block = self - .block() - .selected(selected && matches!(&self.selected, CpuGraphSelection::Legend)) - .expanded(expanded) - .hide_title(true); - - let legend_data = self - .display_data - .iter() - .enumerate() - .map(|(cpu_index, core_data)| { - let style = Some(if cpu_index == 0 { - painter.colours.all_colour_style - } else if self.showing_avg && cpu_index == 1 { - painter.colours.avg_colour_style - } else { - let cpu_style_index = if self.showing_avg { - // No underflow should occur, as if cpu_index was - // 1 and avg is showing, it's caught by the above case! - cpu_index - 2 - } else { - cpu_index - 1 - }; - painter.colours.cpu_colour_styles - [cpu_style_index % painter.colours.cpu_colour_styles.len()] - }); - - vec![ - ( - core_data.cpu_name.clone().into(), - Some(core_data.short_cpu_name.clone().into()), - style, - ), - (core_data.legend_value.clone().into(), None, style), - ] - }) - .collect::<Vec<_>>(); - - self.legend.draw_tui_table( - painter, - f, - &legend_data, - legend_block, - legend_block_area, - true, - false, - ); } fn update_data(&mut self, data_collection: &DataCollection) { - // TODO: *Maybe* look into only taking in enough data for the current retention? Though this isn't great, it means you have to be like process with the whole updating thing. - convert_cpu_data_points(data_collection, &mut self.display_data, false); // TODO: Again, the "is_frozen" is probably useless + convert_cpu_data_points(data_collection, &mut self.display_data); self.load_avg_data = data_collection.load_avg_harvest; } @@ -306,4 +306,46 @@ impl Widget for CpuGraph { fn height(&self) -> LayoutRule { self.height } + + fn handle_widget_selection_left(&mut self) -> SelectionAction { + match self.legend_position { + CpuGraphLegendPosition::Left => { + if let CpuGraphSelection::Graph = self.selected { + self.selected = CpuGraphSelection::Legend; + SelectionAction::Handled + } else { + SelectionAction::NotHandled + } + } + CpuGraphLegendPosition::Right => { + if let CpuGraphSelection::Legend = self.selected { + self.selected = CpuGraphSelection::Graph; + SelectionAction::Handled + } else { + SelectionAction::NotHandled + } + } + } + } + + fn handle_widget_selection_right(&mut self) -> SelectionAction { + match self.legend_position { + CpuGraphLegendPosition::Left => { + if let CpuGraphSelection::Legend = self.selected { + self.selected = CpuGraphSelection::Graph; + SelectionAction::Handled + } else { + SelectionAction::NotHandled + } + } + CpuGraphLegendPosition::Right => { + if let CpuGraphSelection::Graph = self.selected { + self.selected = CpuGraphSelection::Legend; + SelectionAction::Handled + } else { + SelectionAction::NotHandled + } + } + } + } } diff --git a/src/app/widgets/bottom_widgets/mem.rs b/src/app/widgets/bottom_widgets/mem.rs index 1531290b..11880421 100644 --- a/src/app/widgets/bottom_widgets/mem.rs +++ b/src/app/widgets/bottom_widgets/mem.rs @@ -129,8 +129,8 @@ impl Widget for MemGraph { } fn update_data(&mut self, data_collection: &DataCollection) { - self.mem_data = convert_mem_data_points(data_collection, false); // TODO: I think the "is_frozen" part is useless... it's always false now. - self.swap_data = convert_swap_data_points(data_collection, false); + self.mem_data = convert_mem_data_points(data_collection); + self.swap_data = convert_swap_data_points(data_collection); let (memory_labels, swap_labels) = convert_mem_labels(data_collection); self.mem_labels = memory_labels; diff --git a/src/app/widgets/bottom_widgets/net.rs b/src/app/widgets/bottom_widgets/net.rs index d9c0b799..b02b957f 100644 --- a/src/app/widgets/bottom_widgets/net.rs +++ b/src/app/widgets/bottom_widgets/net.rs @@ -568,7 +568,6 @@ impl Widget for NetGraph { fn update_data(&mut self, data_collection: &DataCollection) { let network_data = convert_network_data_points( data_collection, - false, // TODO: I think the is_frozen here is also useless; see mem and cpu false, &self.scale_type, &self.unit_type, @@ -709,7 +708,6 @@ impl Widget for OldNetGraph { fn update_data(&mut self, data_collection: &DataCollection) { let network_data = convert_network_data_points( data_collection, - false, // TODO: I think the is_frozen here is also useless; see mem and cpu true, &self.net_graph.scale_type, &self.net_graph.unit_type, diff --git a/src/app/widgets/bottom_widgets/process.rs b/src/app/widgets/bottom_widgets/process.rs index 87177b22..eeff0b54 100644 --- a/src/app/widgets/bottom_widgets/process.rs +++ b/src/app/widgets/bottom_widgets/process.rs @@ -15,7 +15,7 @@ use tui::{ use crate::{ app::{ data_harvester::processes::ProcessHarvest, - event::{MultiKey, MultiKeyResult, ReturnSignal, WidgetEventResult}, + event::{MultiKey, MultiKeyResult, ReturnSignal, SelectionAction, WidgetEventResult}, query::*, text_table::DesiredColumnWidth, widgets::tui_stuff::BlockBuilder, @@ -575,6 +575,7 @@ impl ProcState { } /// The currently selected part of a [`ProcessManager`] +#[derive(PartialEq, Eq, Clone, Copy)] enum ProcessManagerSelection { Processes, Sort, @@ -775,6 +776,7 @@ pub struct ProcessManager { dd_multi: MultiKey, selected: ProcessManagerSelection, + prev_selected: ProcessManagerSelection, in_tree_mode: bool, show_sort: bool, @@ -819,6 +821,7 @@ impl ProcessManager { search_block_bounds: Rect::default(), dd_multi: MultiKey::register(vec!['d', 'd']), // TODO: Maybe use something static... selected: ProcessManagerSelection::Processes, + prev_selected: ProcessManagerSelection::Processes, in_tree_mode: false, show_sort: false, show_search: false, @@ -871,6 +874,7 @@ impl ProcessManager { WidgetEventResult::NoRedraw } else { self.show_search = true; + self.prev_selected = self.selected; self.selected = ProcessManagerSelection::Search; WidgetEventResult::Redraw } @@ -883,6 +887,7 @@ impl ProcessManager { self.sort_menu .set_index(self.process_table.current_sorting_column_index()); self.show_sort = true; + self.prev_selected = self.selected; self.selected = ProcessManagerSelection::Sort; WidgetEventResult::Redraw } @@ -966,6 +971,7 @@ impl ProcessManager { fn hide_sort(&mut self) { self.show_sort = false; if let ProcessManagerSelection::Sort = self.selected { + self.prev_selected = self.selected; self.selected = ProcessManagerSelection::Processes; } } @@ -973,6 +979,7 @@ impl ProcessManager { fn hide_search(&mut self) { self.show_search = false; if let ProcessManagerSelection::Search = self.selected { + self.prev_selected = self.selected; self.selected = ProcessManagerSelection::Processes; } } @@ -1129,6 +1136,7 @@ impl Component for ProcessManager { if let ProcessManagerSelection::Processes = self.selected { self.process_table.handle_mouse_event(event) } else { + self.prev_selected = self.selected; self.selected = ProcessManagerSelection::Processes; match self.process_table.handle_mouse_event(event) { WidgetEventResult::Quit => WidgetEventResult::Quit, @@ -1142,6 +1150,7 @@ impl Component for ProcessManager { if let ProcessManagerSelection::Sort = self.selected { self.sort_menu.handle_mouse_event(event) } else { + self.prev_selected = self.selected; self.selected = ProcessManagerSelection::Sort; self.sort_menu.handle_mouse_event(event); WidgetEventResult::Redraw @@ -1154,6 +1163,7 @@ impl Component for ProcessManager { if let ProcessManagerSelection::Search = self.selected { self.search_input.handle_mouse_event(event) } else { + self.prev_selected = self.selected; self.selected = ProcessManagerSelection::Search; self.search_input.handle_mouse_event(event); WidgetEventResult::Redraw @@ -1261,9 +1271,11 @@ impl Widget for ProcessManager { area }; + let process_selected = + selected && matches!(self.selected, ProcessManagerSelection::Processes); let process_block = self .block() - .selected(selected && matches!(self.selected, ProcessManagerSelection::Processes)) + .selected(process_selected) .borders(self.block_border) .expanded(expanded && !self.show_sort && !self.show_search); @@ -1273,7 +1285,7 @@ impl Widget for ProcessManager { &self.display_data, process_block, area, - selected, + process_selected, self.show_scroll_index, ); } @@ -1485,4 +1497,69 @@ impl Widget for ProcessManager { fn height(&self) -> LayoutRule { self.height } + + fn handle_widget_selection_left(&mut self) -> SelectionAction { + if self.show_sort { + if let ProcessManagerSelection::Processes = self.selected { + self.prev_selected = self.selected; + self.selected = ProcessManagerSelection::Sort; + SelectionAction::Handled + } else { + SelectionAction::NotHandled + } + } else { + SelectionAction::NotHandled + } + } + + fn handle_widget_selection_right(&mut self) -> SelectionAction { + if self.show_sort { + if let ProcessManagerSelection::Sort = self.selected { + self.prev_selected = self.selected; + self.selected = ProcessManagerSelection::Processes; + SelectionAction::Handled + } else { + SelectionAction::NotHandled + } + } else { + SelectionAction::NotHandled + } + } + + fn handle_widget_selection_up(&mut self) -> SelectionAction { + if self.show_search { + if let ProcessManagerSelection::Search = self.selected { + let prev = self.prev_selected; + self.prev_selected = self.selected; + if self.show_sort && prev == ProcessManagerSelection::Sort { + self.selected = ProcessManagerSelection::Sort; + } else { + self.selected = ProcessManagerSelection::Processes; + } + SelectionAction::Handled + } else { + SelectionAction::NotHandled + } + } else { + SelectionAction::NotHandled + } + } + + fn handle_widget_selection_down(&mut self) -> SelectionAction { + if self.show_search { + if let ProcessManagerSelection::Processes = self.selected { + self.prev_selected = self.selected; + self.selected = ProcessManagerSelection::Search; + SelectionAction::Handled + } else if self.show_sort && self.selected == ProcessManagerSelection::Sort { + self.prev_selected = self.selected; + self.selected = ProcessManagerSelection::Search; + SelectionAction::Handled + } else { + SelectionAction::NotHandled + } + } else { + SelectionAction::NotHandled + } + } } |