summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/history.rs4
-rw-r--r--src/state.rs30
2 files changed, 34 insertions, 0 deletions
diff --git a/src/history.rs b/src/history.rs
index 5397c68..048cc1e 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -194,6 +194,10 @@ impl History {
}
}
}
+
+ pub fn entry_count(&self) -> usize {
+ self.entries.len()
+ }
}
struct HistoryEntry {
diff --git a/src/state.rs b/src/state.rs
index 193d1af..b97249e 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -73,6 +73,36 @@ impl State {
textmode::Key::Ctrl(b'e') => {
ret = false; // fall through and handle normally
}
+ textmode::Key::Char('j') => {
+ let new_focus = match self.focus {
+ Focus::History(idx) => {
+ if idx >= self.history.entry_count() - 1 {
+ Focus::Readline
+ } else {
+ Focus::History(idx + 1)
+ }
+ }
+ Focus::Readline => Focus::Readline,
+ };
+ self.focus = new_focus;
+ self.render().await.unwrap();
+ }
+ textmode::Key::Char('k') => {
+ let new_focus = match self.focus {
+ Focus::History(idx) => {
+ if idx == 0 {
+ Focus::History(0)
+ } else {
+ Focus::History(idx - 1)
+ }
+ }
+ Focus::Readline => {
+ Focus::History(self.history.entry_count() - 1)
+ }
+ };
+ self.focus = new_focus;
+ self.render().await.unwrap();
+ }
textmode::Key::Char('r') => {
self.focus = Focus::Readline;
self.render().await.unwrap();