diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-12 01:56:55 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-12 01:56:55 -0500 |
commit | 8177f123ffb5d312ab664936a22f3e04317c0568 (patch) | |
tree | 2644f3ae3286e35d0ad4aff8116a0beecded25ad /src/state.rs | |
parent | 7f805f31b7a128f37f83e4b80fd89fb9dbf8563a (diff) | |
download | nbsh-8177f123ffb5d312ab664936a22f3e04317c0568.tar.gz nbsh-8177f123ffb5d312ab664936a22f3e04317c0568.zip |
add command to cycle between running programs
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/state.rs b/src/state.rs index 5fb4548..a3d251b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -284,6 +284,12 @@ impl State { ) .await; } + textmode::Key::Char('n') => { + self.set_focus(self.next_running().await, None).await; + } + textmode::Key::Char('p') => { + self.set_focus(self.prev_running().await, None).await; + } textmode::Key::Char('r') => { self.set_focus(Focus::Readline, None).await; } @@ -417,4 +423,26 @@ impl State { } }) } + + async fn next_running(&self) -> Focus { + let count = self.history.entry_count(); + let cur = self.focus_idx().unwrap_or(count); + for idx in ((cur + 1)..count).chain(0..cur) { + if self.history.entry(idx).await.running() { + return Focus::History(idx); + } + } + self.focus_idx().map_or(Focus::Readline, Focus::History) + } + + async fn prev_running(&self) -> Focus { + let count = self.history.entry_count(); + let cur = self.focus_idx().unwrap_or(count); + for idx in ((cur + 1)..count).chain(0..cur).rev() { + if self.history.entry(idx).await.running() { + return Focus::History(idx); + } + } + self.focus_idx().map_or(Focus::Readline, Focus::History) + } } |