diff --git a/CHANGELOG.md b/CHANGELOG.md index eca1b864..0f215ef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Other +- [#950](https://github.com/ClementTsang/bottom/pull/950): Update help menu for disk and temperature widgets with sorting support. + ## [0.7.1] - 2023-01-06 ## Bug Fixes diff --git a/docs/content/assets/screenshots/disk.webp b/docs/content/assets/screenshots/disk.webp index 516652de..f72bd76a 100644 Binary files a/docs/content/assets/screenshots/disk.webp and b/docs/content/assets/screenshots/disk.webp differ diff --git a/docs/content/usage/widgets/disk.md b/docs/content/usage/widgets/disk.md index a7d789d9..bc7fbbeb 100644 --- a/docs/content/usage/widgets/disk.md +++ b/docs/content/usage/widgets/disk.md @@ -33,6 +33,7 @@ Note that key bindings are generally case-sensitive. | ++u++ | Sort by amount used, press again to reverse sorting order | | ++n++ | Sort by amount free, press again to reverse sorting order | | ++t++ | Sort by total space available, press again to reverse sorting order | +| ++p++ | Sort by percentage used, press again to reverse sorting order | | ++r++ | Sort by read rate, press again to reverse sorting order | | ++w++ | Sort by write rate, press again to reverse sorting order | diff --git a/src/app.rs b/src/app.rs index bad8667b..311aceb1 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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 = 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(); + } }