other: re-enable disk usage split, update help menu (#963)

* Revert "other: revert disk usage change for now (#962)"

This reverts commit d3661c2320.

* some cleanup

* update help menu

* update screenshot

* update changelog wording

* Remove redundant newlines

* Use type system to ensure help constants match in size
This commit is contained in:
Clement Tsang 2023-01-19 05:40:34 -05:00 committed by GitHub
parent 0a83456adb
commit 22e386a38c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 73 additions and 32 deletions

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -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 |

View File

@ -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(),

View File

@ -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

View File

@ -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

View File

@ -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"
)
}
}

View File

@ -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();
}
}