Skip to content

Commit

Permalink
fix(console): enable view-switching keystrokes on details views (#387)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arifd committed Nov 17, 2022
1 parent 06531a9 commit d98f159
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions tokio-console/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -110,9 +121,6 @@ impl View {
));
}
}
key!(Char('r')) => {
self.state = ResourcesList;
}
_ => {
// otherwise pass on to view
self.tasks_list.update_input(event);
Expand All @@ -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);
Expand Down

0 comments on commit d98f159

Please sign in to comment.