From 8177f123ffb5d312ab664936a22f3e04317c0568 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 12 Dec 2021 01:56:55 -0500 Subject: add command to cycle between running programs --- src/state.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/state.rs') 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) + } } -- cgit v1.2.3-54-g00ecf