From f417d7a32561d91a355a38b200e4c8481d3c93da Mon Sep 17 00:00:00 2001 From: Arif Driessen Date: Thu, 17 Nov 2022 19:41:46 +0100 Subject: [PATCH] fix(console): enable view-switching keystrokes on details views (#387) Currently, the help text for the `r` and `t` keystrokes to switch to the Resources and Tasks views is shown on the Task Details and Resource Details views, as well as on the Task List and Resource List views. See this screenshot for an example: ![image](https://user-images.githubusercontent.com/2345750/202058962-4a8f062c-78fd-47eb-a3b1-5de470976aa8.png) However, the keystrokes are not actually handled while the console is showing a details view. This branch changes the console to handle the `r` and `t` keystrokes on all views. This also simplifies the keyboard input code somewhat. --- Cargo.lock | 2 +- tokio-console/src/view/mod.rs | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31f14e8be..615baa841 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -280,7 +280,7 @@ dependencies = [ [[package]] name = "console-subscriber" -version = "0.1.7" +version = "0.1.8" dependencies = [ "console-api", "crossbeam-channel", diff --git a/tokio-console/src/view/mod.rs b/tokio-console/src/view/mod.rs index e22d239af..8f1d5429d 100644 --- a/tokio-console/src/view/mod.rs +++ b/tokio-console/src/view/mod.rs @@ -96,6 +96,17 @@ impl View { pub(crate) fn update_input(&mut self, event: input::Event, state: &State) -> UpdateKind { use ViewState::*; let mut update_kind = UpdateKind::Other; + + if matches!(event, key!(Char('t'))) { + self.state = TasksList; + return update_kind; + } + + if matches!(event, key!(Char('r'))) { + self.state = ResourcesList; + return update_kind; + } + match self.state { TasksList => { // The enter key changes views, so handle here since we can @@ -110,9 +121,6 @@ impl View { )); } } - key!(Char('r')) => { - self.state = ResourcesList; - } _ => { // otherwise pass on to view self.tasks_list.update_input(event); @@ -127,9 +135,6 @@ impl View { self.state = ResourceInstance(self::resource::ResourceView::new(res)); } } - key!(Char('t')) => { - self.state = TasksList; - } _ => { // otherwise pass on to view self.resources_list.update_input(event);