other: clean up help text spacing + help text dialog sizing (#1865)

* other: clean up help text spacing + help text dialog sizing

* use 'safer' saturating, I think it gets optimized out...?

* semicolon + typo
This commit is contained in:
Clement Tsang 2025-11-15 13:56:10 -05:00 committed by GitHub
parent d32b50351f
commit c97cb063d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 155 additions and 133 deletions

View File

@ -11,7 +11,7 @@ mod widgets;
use tui::{ use tui::{
Frame, Terminal, Frame, Terminal,
backend::Backend, backend::Backend,
layout::{Constraint, Direction, Layout, Rect}, layout::{Constraint, Direction, Flex, Layout, Rect},
text::Span, text::Span,
widgets::Paragraph, widgets::Paragraph,
}; };
@ -122,35 +122,61 @@ impl Painter {
if app_state.help_dialog_state.is_showing_help { if app_state.help_dialog_state.is_showing_help {
let gen_help_len = GENERAL_HELP_TEXT.len() as u16 + 3; let gen_help_len = GENERAL_HELP_TEXT.len() as u16 + 3;
let border_len = terminal_height.saturating_sub(gen_help_len) / 2; let border_len = terminal_height.saturating_sub(gen_help_len) / 2;
let vertical_dialog_chunk = Layout::default() let [_, vertical_dialog_chunk, _] = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints([ .constraints([
Constraint::Length(border_len), Constraint::Length(border_len),
Constraint::Length(gen_help_len), Constraint::Length(gen_help_len),
Constraint::Length(border_len), Constraint::Length(border_len),
]) ])
.split(terminal_size); .areas(terminal_size);
let middle_dialog_chunk = Layout::default() // An approximate proxy for the max line length to use.
.direction(Direction::Horizontal) const MAX_TEXT_LENGTH: u16 = const {
.constraints(if terminal_width < 100 { let mut max = 0;
// TODO: [REFACTOR] The point we start changing size at currently hard-coded
// in. let mut i = 0;
[ while i < HELP_TEXT.len() {
Constraint::Percentage(0), let section = HELP_TEXT[i];
Constraint::Percentage(100), let mut j = 0;
Constraint::Percentage(0), while j < section.len() {
] let line = section[j];
if line.len() > max {
max = line.len();
}
j += 1;
}
i += 1;
}
max as u16
};
let dialog_width = vertical_dialog_chunk.width;
let [middle_dialog_chunk] = if dialog_width < MAX_TEXT_LENGTH {
Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(100)])
.areas(vertical_dialog_chunk)
} else {
// We calculate this so that the margins never have to split an odd number.
let len = if (dialog_width.saturating_sub(MAX_TEXT_LENGTH)) % 2 == 0 {
MAX_TEXT_LENGTH
} else { } else {
[ // It can only be 1 if the difference is greater than 1, so this is fine.
Constraint::Percentage(15), MAX_TEXT_LENGTH + 1
Constraint::Percentage(70), };
Constraint::Percentage(15),
]
})
.split(vertical_dialog_chunk[1]);
self.draw_help_dialog(f, app_state, middle_dialog_chunk[1]); Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Length(len)])
.flex(Flex::SpaceAround)
.areas(vertical_dialog_chunk)
};
self.draw_help_dialog(f, app_state, middle_dialog_chunk);
} else if app_state.process_kill_dialog.is_open() { } else if app_state.process_kill_dialog.is_open() {
// FIXME: For width, just limit to a max size or full width. For height, not sure. Maybe pass max and let child handle? // FIXME: For width, just limit to a max size or full width. For height, not sure. Maybe pass max and let child handle?
let horizontal_padding = if terminal_width < 100 { 0 } else { 5 }; let horizontal_padding = if terminal_width < 100 { 0 } else { 5 };

View File

@ -25,159 +25,155 @@ const HELP_CONTENTS_TEXT: [&str; 10] = [
// TODO [Help]: Search in help? // TODO [Help]: Search in help?
// TODO [Help]: Move to using tables for easier formatting? // TODO [Help]: Move to using tables for easier formatting?
pub(crate) const GENERAL_HELP_TEXT: [&str; 32] = [ pub(crate) const GENERAL_HELP_TEXT: [&str; 28] = [
"1 - General", "1 - General",
"q, Ctrl-c Quit", "q, Ctrl-c Quit",
"Esc Close dialog windows, search, widgets, or exit expanded mode", "Esc Close dialog windows, search, widgets, or exit expanded mode",
"Ctrl-r Reset display and any collected data", "Ctrl-r Reset display and any collected data",
"f Freeze/unfreeze updating with new data", "f Freeze/unfreeze updating with new data",
"Ctrl-Left, ", "Ctrl-Left, ",
"Shift-Left, Move widget selection left", "Shift-Left, H, A Move widget selection left",
"H, A ", "Ctrl-Right, ",
"Ctrl-Right, ", "Shift-Right, L, D Move widget selection right",
"Shift-Right, Move widget selection right", "Ctrl-Up, ",
"L, D ", "Shift-Up, K, W Move widget selection up",
"Ctrl-Up, ", "Ctrl-Down, ",
"Shift-Up, Move widget selection up", "Shift-Down, J, S Move widget selection down",
"K, W ", "Left, h Move left within widget",
"Ctrl-Down, ", "Down, j Move down within widget",
"Shift-Down, Move widget selection down", "Up, k Move up within widget",
"J, S ", "Right, l Move right within widget",
"Left, h Move left within widget", "? Open help menu",
"Down, j Move down within widget", "gg Jump to the first entry",
"Up, k Move up within widget", "G Jump to the last entry",
"Right, l Move right within widget", "e Toggle expanding the currently selected widget",
"? Open help menu", "+ Zoom in on chart (decrease time range)",
"gg Jump to the first entry", "- Zoom out on chart (increase time range)",
"G Jump to the last entry", "= Reset zoom",
"e Toggle expanding the currently selected widget", "PgUp, PgDown Scroll up/down a table by a page",
"+ Zoom in on chart (decrease time range)", "Ctrl-u, Ctrl-d Scroll up/down a table by half a page",
"- Zoom out on chart (increase time range)", "Mouse scroll Scroll through the tables or zoom in/out of charts by scrolling up/down",
"= Reset zoom", "Mouse click Selects the clicked widget, table entry, dialog option, or tab",
"PgUp, PgDown Scroll up/down a table by a page",
"Ctrl-u, Ctrl-d Scroll up/down a table by half a page",
"Mouse scroll Scroll through the tables or zoom in/out of charts by scrolling up/down",
"Mouse click Selects the clicked widget, table entry, dialog option, or tab",
]; ];
const CPU_HELP_TEXT: [&str; 2] = [ const CPU_HELP_TEXT: [&str; 2] = [
"2 - CPU widget", "2 - CPU widget",
"Mouse scroll Scrolling over an CPU core/average shows only that entry on the chart", "Mouse scroll Scrolling over a CPU core/average shows only that entry on the chart",
]; ];
const PROCESS_HELP_TEXT: [&str; 20] = [ const PROCESS_HELP_TEXT: [&str; 20] = [
"3 - Process widget", "3 - Process widget",
"dd, F9, Delete Kill the selected process", "dd, F9, Delete Kill the selected process",
"c Sort by CPU usage, press again to reverse", "c Sort by CPU usage, press again to reverse",
"m Sort by memory usage, press again to reverse", "m Sort by memory usage, press again to reverse",
"p Sort by PID name, press again to reverse", "p Sort by PID name, press again to reverse",
"n Sort by process name, press again to reverse", "n Sort by process name, press again to reverse",
"Tab Group/un-group processes with the same name", "Tab Group/un-group processes with the same name",
"Ctrl-f, / Open process search widget", "Ctrl-f, / Open process search widget",
"P Toggle between showing the full command or just the process name", "P Toggle between showing the full command or just the process name",
"s, F6 Open process sort widget", "s, F6 Open process sort widget",
"I Invert current sort", "I Invert current sort",
"% Toggle between values and percentages for memory usage", "% Toggle between values and percentages for memory usage",
"t, F5 Toggle tree mode", "t, F5 Toggle tree mode",
"Right Collapse a branch while in tree mode", "Right Collapse a branch while in tree mode",
"Left Expand a branch while in tree mode", "Left Expand a branch while in tree mode",
"+, -, click Toggle whether a branch is expanded or collapsed in tree mode", "+, -, click Toggle whether a branch is expanded or collapsed in tree mode",
"click on header Sorts the entries by that column, click again to invert the sort", "click on header Sorts the entries by that column, click again to invert the sort",
"C Sort by GPU usage, press again to reverse", "C Sort by GPU usage, press again to reverse",
"M Sort by GPU memory usage, press again to reverse", "M Sort by GPU memory usage, press again to reverse",
"z Toggle the display of kernel threads", "z Toggle the display of kernel threads",
]; ];
const SEARCH_HELP_TEXT: [&str; 51] = [ const SEARCH_HELP_TEXT: [&str; 51] = [
"4 - Process search widget", "4 - Process search widget",
"Esc Close the search widget (retains the filter)", "Esc Close the search widget (retains the filter)",
"Ctrl-a Skip to the start of the search query", "Ctrl-a Skip to the start of the search query",
"Ctrl-e Skip to the end of the search query", "Ctrl-e Skip to the end of the search query",
"Ctrl-u Clear the current search query", "Ctrl-u Clear the current search query",
"Ctrl-w Delete a word behind the cursor", "Ctrl-w Delete a word behind the cursor",
"Ctrl-h Delete the character behind the cursor", "Ctrl-h Delete the character behind the cursor",
"Backspace Delete the character behind the cursor", "Backspace Delete the character behind the cursor",
"Delete Delete the character at the cursor", "Delete Delete the character at the cursor",
"Alt-c, F1 Toggle matching case", "Alt-c, F1 Toggle matching case",
"Alt-w, F2 Toggle matching the entire word", "Alt-w, F2 Toggle matching the entire word",
"Alt-r, F3 Toggle using regex", "Alt-r, F3 Toggle using regex",
"Left, Alt-h Move cursor left", "Left, Alt-h Move cursor left",
"Right, Alt-l Move cursor right", "Right, Alt-l Move cursor right",
"", "",
"Supported search types:", "Supported search types:",
"<by name/cmd> ex: btm", "<by name/cmd> ex: btm",
"pid ex: pid 825", "pid ex: pid 825",
"cpu, cpu% ex: cpu > 4.2", "cpu, cpu% ex: cpu > 4.2",
"mem, mem% ex: mem < 4.2", "mem, mem% ex: mem < 4.2",
"memb ex: memb < 100 kb", "memb ex: memb < 100 kb",
"read, r/s, rps ex: read >= 1 b", "read, r/s, rps ex: read >= 1 b",
"write, w/s, wps ex: write <= 1 tb", "write, w/s, wps ex: write <= 1 tb",
"tread, t.read ex: tread = 1", "tread, t.read ex: tread = 1",
"twrite, t.write ex: twrite = 1", "twrite, t.write ex: twrite = 1",
"user ex: user = root", "user ex: user = root",
"state ex: state = running", "state ex: state = running",
"gpu% ex: gpu% < 4.2", "gpu% ex: gpu% < 4.2",
"gmem ex: gmem < 100 kb", "gmem ex: gmem < 100 kb",
"gmem% ex: gmem% < 4.2", "gmem% ex: gmem% < 4.2",
"", "",
"Comparison operators:", "Comparison operators:",
"= ex: cpu = 1", "= ex: cpu = 1",
"> ex: cpu > 1", "> ex: cpu > 1",
"< ex: cpu < 1", "< ex: cpu < 1",
">= ex: cpu >= 1", ">= ex: cpu >= 1",
"<= ex: cpu <= 1", "<= ex: cpu <= 1",
"", "",
"Logical operators:", "Logical operators:",
"and, &&, <Space> ex: btm and cpu > 1 and mem > 1", "and, &&, <Space> ex: btm and cpu > 1 and mem > 1",
"or, || ex: btm or firefox", "or, || ex: btm or firefox",
"", "",
"Supported units:", "Supported units:",
"B ex: read > 1 b", "B ex: read > 1 b",
"KB ex: read > 1 kb", "KB ex: read > 1 kb",
"MB ex: read > 1 mb", "MB ex: read > 1 mb",
"TB ex: read > 1 tb", "TB ex: read > 1 tb",
"KiB ex: read > 1 kib", "KiB ex: read > 1 kib",
"MiB ex: read > 1 mib", "MiB ex: read > 1 mib",
"GiB ex: read > 1 gib", "GiB ex: read > 1 gib",
"TiB ex: read > 1 tib", "TiB ex: read > 1 tib",
]; ];
const SORT_HELP_TEXT: [&str; 6] = [ const SORT_HELP_TEXT: [&str; 6] = [
"5 - Sort widget", "5 - Sort widget",
"Down, 'j' Scroll down in list", "Down, 'j' Scroll down in list",
"Up, 'k' Scroll up in list", "Up, 'k' Scroll up in list",
"Mouse scroll Scroll through sort widget", "Mouse scroll Scroll through sort widget",
"Esc Close the sort widget", "Esc Close the sort widget",
"Enter Sort by current selected column", "Enter Sort by current selected column",
]; ];
const TEMP_HELP_WIDGET: [&str; 3] = [ const TEMP_HELP_WIDGET: [&str; 3] = [
"6 - Temperature widget", "6 - Temperature widget",
"'s' Sort by sensor name, press again to reverse", "'s' Sort by sensor name, press again to reverse",
"'t' Sort by temperature, press again to reverse", "'t' Sort by temperature, press again to reverse",
]; ];
const DISK_HELP_WIDGET: [&str; 9] = [ const DISK_HELP_WIDGET: [&str; 9] = [
"7 - Disk widget", "7 - Disk widget",
"'d' Sort by disk name, press again to reverse", "'d' Sort by disk name, press again to reverse",
"'m' Sort by disk mount, press again to reverse", "'m' Sort by disk mount, press again to reverse",
"'u' Sort by disk usage, press again to reverse", "'u' Sort by disk usage, press again to reverse",
"'n' Sort by disk free space, press again to reverse", "'n' Sort by disk free space, press again to reverse",
"'t' Sort by total disk 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", "'p' Sort by disk usage percentage, press again to reverse",
"'r' Sort by disk read activity, press again to reverse", "'r' Sort by disk read activity, press again to reverse",
"'w' Sort by disk write activity, press again to reverse", "'w' Sort by disk write activity, press again to reverse",
]; ];
const BATTERY_HELP_TEXT: [&str; 3] = [ const BATTERY_HELP_TEXT: [&str; 3] = [
"8 - Battery widget", "8 - Battery widget",
"Left Go to previous battery", "Left Go to previous battery",
"Right Go to next battery", "Right Go to next battery",
]; ];
const BASIC_MEM_HELP_TEXT: [&str; 2] = [ const BASIC_MEM_HELP_TEXT: [&str; 2] = [
"9 - Basic memory widget", "9 - Basic memory widget",
"% Toggle between values and percentages for memory usage", "% Toggle between values and percentages for memory usage",
]; ];
pub(crate) const HELP_TEXT: [&[&str]; HELP_CONTENTS_TEXT.len()] = [ pub(crate) const HELP_TEXT: [&[&str]; HELP_CONTENTS_TEXT.len()] = [