diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2023-01-19 05:40:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-19 05:40:34 -0500 |
commit | 22e386a38c713c8aa7045e04b7d8c8e7216f7074 (patch) | |
tree | a31d31cae91d8ff6dfac95ed7cc61405d6f91c6c /src | |
parent | 0a83456adb0e1cbdcfee1fa05eb32cf645d6783e (diff) |
other: re-enable disk usage split, update help menu (#963)
* Revert "other: revert disk usage change for now (#962)"
This reverts commit d3661c23200a66c7dc01f4e534d8d7e97dc188d2.
* some cleanup
* update help menu
* update screenshot
* update changelog wording
* Remove redundant newlines
* Use type system to ensure help constants match in size
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 26 | ||||
-rw-r--r-- | src/canvas.rs | 2 | ||||
-rw-r--r-- | src/canvas/dialogs/help_dialog.rs | 4 | ||||
-rw-r--r-- | src/constants.rs | 60 | ||||
-rw-r--r-- | src/widgets/disk_table.rs | 10 |
5 files changed, 70 insertions, 32 deletions
@@ -1159,8 +1159,7 @@ impl App { .disk_state .get_mut_widget_state(self.current_widget.widget_id) { - disk.table.set_sort_index(0); - disk.force_data_update(); + disk.set_index(0); } } 'g' => { @@ -1207,8 +1206,7 @@ impl App { .disk_state .get_mut_widget_state(self.current_widget.widget_id) { - disk.table.set_sort_index(1); - disk.force_data_update(); + disk.set_index(1); } } 'p' => { @@ -1219,6 +1217,11 @@ impl App { { proc_widget_state.select_column(ProcWidget::PID_OR_COUNT); } + } else if let Some(disk) = self + .disk_state + .get_mut_widget_state(self.current_widget.widget_id) + { + disk.set_index(5); } } 'P' => { @@ -1243,8 +1246,7 @@ impl App { .disk_state .get_mut_widget_state(self.current_widget.widget_id) { - disk.table.set_sort_index(3); - disk.force_data_update(); + disk.set_index(3); } } '?' => { @@ -1268,8 +1270,7 @@ impl App { .disk_state .get_mut_widget_state(self.current_widget.widget_id) { - disk.table.set_sort_index(4); - disk.force_data_update(); + disk.set_index(4); } } '+' => self.on_plus(), @@ -1293,8 +1294,7 @@ impl App { .disk_state .get_mut_widget_state(self.current_widget.widget_id) { - disk.table.set_sort_index(2); - disk.force_data_update(); + disk.set_index(2); } } 'r' => { @@ -1302,8 +1302,7 @@ impl App { .disk_state .get_mut_widget_state(self.current_widget.widget_id) { - disk.table.set_sort_index(5); - disk.force_data_update(); + disk.set_index(6); } } 'w' => { @@ -1311,8 +1310,7 @@ impl App { .disk_state .get_mut_widget_state(self.current_widget.widget_id) { - disk.table.set_sort_index(6); - disk.force_data_update(); + disk.set_index(7); } } 'I' => self.invert_sort(), diff --git a/src/canvas.rs b/src/canvas.rs index 2ef29b4e..b1eca362 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -187,7 +187,7 @@ impl Painter { let mut styled_help_spans = Vec::new(); // Init help text: - (*HELP_TEXT).iter().enumerate().for_each(|(itx, section)| { + HELP_TEXT.iter().enumerate().for_each(|(itx, section)| { if itx == 0 { styled_help_spans.extend( section diff --git a/src/canvas/dialogs/help_dialog.rs b/src/canvas/dialogs/help_dialog.rs index cd61db74..66741223 100644 --- a/src/canvas/dialogs/help_dialog.rs +++ b/src/canvas/dialogs/help_dialog.rs @@ -77,9 +77,7 @@ impl Painter { }); let max_scroll_index = &mut app_state.help_dialog_state.scroll_state.max_scroll_index; - *max_scroll_index = (self.styled_help_text.len() as u16 - + (constants::HELP_TEXT.len() as u16 - 5) - + overflow_buffer) + *max_scroll_index = (self.styled_help_text.len() as u16 + 3 + overflow_buffer) .saturating_sub(draw_loc.height + 1); // Fix if over-scrolled diff --git a/src/constants.rs b/src/constants.rs index 4c5fac59..bc472fd0 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -261,15 +261,17 @@ pub static NORD_LIGHT_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigC }); // Help text -pub const HELP_CONTENTS_TEXT: [&str; 8] = [ +pub const HELP_CONTENTS_TEXT: [&str; 10] = [ "Either scroll or press the number key to go to the corresponding help menu section:", "1 - General", "2 - CPU widget", "3 - Process widget", "4 - Process search widget", "5 - Process sort widget", - "6 - Battery widget", - "7 - Basic memory widget", + "6 - Temperature widget", + "7 - Disk widget", + "8 - Battery widget", + "9 - Basic memory widget", ]; // TODO [Help]: Search in help? @@ -310,17 +312,17 @@ pub const GENERAL_HELP_TEXT: [&str; 32] = [ ]; pub const CPU_HELP_TEXT: [&str; 2] = [ - "2 - CPU widget\n", + "2 - CPU widget", "Mouse scroll Scrolling over an CPU core/average shows only that entry on the chart", ]; pub const PROCESS_HELP_TEXT: [&str; 15] = [ "3 - Process widget", "dd, F9 Kill the selected process", - "c Sort by CPU usage, press again to reverse sorting order", - "m Sort by memory usage, press again to reverse sorting order", - "p Sort by PID name, press again to reverse sorting order", - "n Sort by process name, press again to reverse sorting order", + "c Sort by CPU usage, press again to reverse", + "m Sort by memory usage, press again to reverse", + "p Sort by PID name, press again to reverse", + "n Sort by process name, press again to reverse", "Tab Group/un-group processes with the same name", "Ctrl-f, / Open process search widget", "P Toggle between showing the full command or just the process name", @@ -384,7 +386,7 @@ pub const SEARCH_HELP_TEXT: [&str; 48] = [ ]; pub const SORT_HELP_TEXT: [&str; 6] = [ - "5 - Sort widget\n", + "5 - Sort widget", "Down, 'j' Scroll down in list", "Up, 'k' Scroll up in list", "Mouse scroll Scroll through sort widget", @@ -392,24 +394,44 @@ pub const SORT_HELP_TEXT: [&str; 6] = [ "Enter Sort by current selected column", ]; +pub const TEMP_HELP_WIDGET: [&str; 3] = [ + "6 - Temperature widget", + "'s' Sort by sensor name, press again to reverse", + "'t' Sort by temperature, press again to reverse", +]; + +pub const DISK_HELP_WIDGET: [&str; 9] = [ + "7 - Disk widget", + "'d' Sort by disk name, press again to reverse", + "'m' Sort by disk mount, press again to reverse", + "'u' Sort by disk usage, press again to reverse", + "'n' Sort by disk free space, press again to reverse", + "'t' Sort by total disk space, press again to reverse", + "'p' Sort by disk usage percentage, press again to reverse", + "'r' Sort by disk read activity, press again to reverse", + "'w' Sort by disk write activity, press again to reverse", +]; + pub const BATTERY_HELP_TEXT: [&str; 3] = [ - "6 - Battery widget", + "8 - Battery widget", "Left Go to previous battery", "Right Go to next battery", ]; pub const BASIC_MEM_HELP_TEXT: [&str; 2] = [ - "7 - Basic memory widget", + "9 - Basic memory widget", "% Toggle between values and percentages for memory usage", ]; -pub const HELP_TEXT: &[&[&str]] = &[ +pub const HELP_TEXT: [&[&str]; HELP_CONTENTS_TEXT.len()] = [ &HELP_CONTENTS_TEXT, &GENERAL_HELP_TEXT, &CPU_HELP_TEXT, &PROCESS_HELP_TEXT, &SEARCH_HELP_TEXT, &SORT_HELP_TEXT, + &TEMP_HELP_WIDGET, + &DISK_HELP_WIDGET, &BATTERY_HELP_TEXT, &BASIC_MEM_HELP_TEXT, ]; @@ -691,3 +713,17 @@ pub const CONFIG_LAYOUT_HEAD: &str = r##" pub const CONFIG_FILTER_HEAD: &str = r##" # These options represent disabled entries for the temperature and disk widgets. "##; + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn help_menu_matches_entry_len() { + assert_eq!( + HELP_CONTENTS_TEXT.len(), + HELP_TEXT.len(), + "the two should be equal, or this test should be updated" + ) + } +} diff --git a/src/widgets/disk_table.rs b/src/widgets/disk_table.rs index 25b5af61..19bee86f 100644 --- a/src/widgets/disk_table.rs +++ b/src/widgets/disk_table.rs @@ -111,7 +111,7 @@ impl ColumnHeader for DiskWidgetColumn { DiskWidgetColumn::Mount => "Mount(m)", DiskWidgetColumn::Used => "Used(u)", DiskWidgetColumn::Free => "Free(n)", - DiskWidgetColumn::UsedPercent => "Used(u)", + DiskWidgetColumn::UsedPercent => "Used%(p)", DiskWidgetColumn::FreePercent => "Free%", DiskWidgetColumn::Total => "Total(t)", DiskWidgetColumn::IoRead => "R/s(r)", @@ -213,9 +213,10 @@ impl DiskTableWidget { let columns = [ SortColumn::soft(DiskWidgetColumn::Disk, Some(0.2)), SortColumn::soft(DiskWidgetColumn::Mount, Some(0.2)), - SortColumn::hard(DiskWidgetColumn::UsedPercent, 9).default_descending(), + SortColumn::hard(DiskWidgetColumn::Used, 8).default_descending(), SortColumn::hard(DiskWidgetColumn::Free, 8).default_descending(), SortColumn::hard(DiskWidgetColumn::Total, 9).default_descending(), + SortColumn::hard(DiskWidgetColumn::UsedPercent, 9).default_descending(), SortColumn::hard(DiskWidgetColumn::IoRead, 10).default_descending(), SortColumn::hard(DiskWidgetColumn::IoWrite, 11).default_descending(), ]; @@ -254,4 +255,9 @@ impl DiskTableWidget { } self.table.set_data(data); } + + pub fn set_index(&mut self, index: usize) { + self.table.set_sort_index(index); + self.force_data_update(); + } } |