summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/state.rs28
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)
+ }
}