From c813b220af3e0e29646d6f301b291f6534622035 Mon Sep 17 00:00:00 2001 From: Adarsh Das <59739923+Saphereye@users.noreply.github.com> Date: Mon, 17 Nov 2025 04:04:35 +0530 Subject: [PATCH] feature: add spacebar shortcut to toggle process tree nodes (#1830) * feature: added spacebar as a toggle for proc tree mode * bug: added check if the app is currently in search widget state * refactor: moved the if statements inside the match case * docs: added documentation for Spaec as tree toggle * revert: changes * feat: added space key to toggle tree * refactor: clippy errors * docs: updated documentation for space as toggle * feat: experimental change to Minus, collapse entire tree * fix: clippy errors * feat: finished - and + as full tree collapse/expand * refactor: clippy errors * Made the all collapse function more concise * Changed i32 calls to Pid * updated help text * Fixed array * reverted total collapse and expand of trees * array fix --- docs/content/usage/widgets/process.md | 2 +- src/app.rs | 17 ++++++++++++ src/constants.rs | 38 +++++++++++++-------------- src/event.rs | 6 ++--- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/docs/content/usage/widgets/process.md b/docs/content/usage/widgets/process.md index cadc63f3..6f7ae1aa 100644 --- a/docs/content/usage/widgets/process.md +++ b/docs/content/usage/widgets/process.md @@ -101,7 +101,7 @@ Pressing ++t++ or ++f5++ in the table toggles tree mode in the process widget, d A process in tree mode can also be "collapsed", hiding its children and any descendants, using the either the ++minus++, ++plus++, or ++left++ keys, or clicking on an entry. It can be expanded by using the ++minus++, ++plus++, or ++right++ -keys, or by clicking on the entry again. +keys, or by clicking on the entry again. The ++space++ key can also be used to toggle between the collapsed and expanded states. !!! info diff --git a/src/app.rs b/src/app.rs index 2e3188a2..076b2776 100644 --- a/src/app.rs +++ b/src/app.rs @@ -684,6 +684,23 @@ impl App { } } + pub fn on_space_key(&mut self) { + if !self.is_in_dialog() { + if self.current_widget.widget_type == BottomWidgetType::Proc { + if let Some(proc_widget_state) = self + .states + .proc_state + .get_mut_widget_state(self.current_widget.widget_id) + { + proc_widget_state.toggle_current_tree_branch_entry(); + } + } + } else if self.process_kill_dialog.is_open() { + // Either select the current option, + // or scroll to the next one + } + } + pub fn on_page_up(&mut self) { if self.process_kill_dialog.is_open() { self.process_kill_dialog.on_page_up(); diff --git a/src/constants.rs b/src/constants.rs index 927697f5..157b72aa 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -63,25 +63,25 @@ const CPU_HELP_TEXT: [&str; 2] = [ const PROCESS_HELP_TEXT: [&str; 20] = [ "3 - Process widget", - "dd, F9, Delete Kill the selected process", - "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", - "s, F6 Open process sort widget", - "I Invert current sort", - "% Toggle between values and percentages for memory usage", - "t, F5 Toggle tree mode", - "Right Collapse 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 on header Sorts the entries by that column, click again to invert the sort", - "C Sort by GPU usage, press again to reverse", - "M Sort by GPU memory usage, press again to reverse", - "z Toggle the display of kernel threads", + "dd, F9, Delete Kill the selected process", + "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", + "s, F6 Open process sort widget", + "I Invert current sort", + "% Toggle between values and percentages for memory usage", + "t, F5 Toggle tree mode", + "Right Collapse a branch while in tree mode", + "Left Expand a branch while in tree mode", + "+, -, click, Space 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", + "C Sort by GPU usage, press again to reverse", + "M Sort by GPU memory usage, press again to reverse", + "z Toggle the display of kernel threads", ]; const SEARCH_HELP_TEXT: [&str; 51] = [ diff --git a/src/event.rs b/src/event.rs index 44afe576..f3dc620b 100644 --- a/src/event.rs +++ b/src/event.rs @@ -56,17 +56,15 @@ pub fn handle_key_event_or_break( // c_debug!("KeyEvent: {event:?}"); if event.modifiers.is_empty() { - // Required catch for searching - otherwise you couldn't search with q. - if event.code == KeyCode::Char('q') && !app.is_in_search_widget() { - return true; - } match event.code { + KeyCode::Char('q') if !app.is_in_search_widget() => return true, KeyCode::End => app.skip_to_last(), KeyCode::Home => app.skip_to_first(), KeyCode::Up => app.on_up_key(), KeyCode::Down => app.on_down_key(), KeyCode::Left => app.on_left_key(), KeyCode::Right => app.on_right_key(), + KeyCode::Char(' ') if !app.is_in_search_widget() => app.on_space_key(), KeyCode::Char(caught_char) => app.on_char_key(caught_char), KeyCode::Esc => app.on_esc(), KeyCode::Enter => app.on_enter(),