summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-10 23:07:08 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-10 23:07:08 -0500
commita87e03fa707cfdd9779334d4bf177188bb54db5b (patch)
tree8133f5d896ac433268c88e1e3e41b96d1ed78b9a
parented83c606b26affee61d8745bbc9cd9601f8a52e6 (diff)
downloadnbsh-a87e03fa707cfdd9779334d4bf177188bb54db5b.tar.gz
nbsh-a87e03fa707cfdd9779334d4bf177188bb54db5b.zip
space to recall focused command to the readline
-rw-r--r--src/history.rs4
-rw-r--r--src/readline.rs5
-rw-r--r--src/state.rs11
3 files changed, 20 insertions, 0 deletions
diff --git a/src/history.rs b/src/history.rs
index 93fcaa4..2753470 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -138,6 +138,10 @@ impl History {
self.entries[idx].lock_arc().await.running()
}
+ pub async fn history_cmd(&self, idx: usize) -> String {
+ self.entries[idx].lock_arc().await.cmd.clone()
+ }
+
pub fn entry_count(&self) -> usize {
self.entries.len()
}
diff --git a/src/readline.rs b/src/readline.rs
index 37c466f..306fed9 100644
--- a/src/readline.rs
+++ b/src/readline.rs
@@ -120,6 +120,11 @@ impl Readline {
self.pos += s.chars().count();
}
+ pub fn set_input(&mut self, s: &str) {
+ self.input_line = s.to_string();
+ self.pos = s.chars().count();
+ }
+
fn backspace(&mut self) {
while self.pos > 0 {
self.pos -= 1;
diff --git a/src/state.rs b/src/state.rs
index c31eba8..9ab76ce 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -139,6 +139,17 @@ impl State {
),
))
}
+ textmode::Key::Char(' ') => {
+ if let Some(idx) = self.focus_idx() {
+ self.readline
+ .set_input(&self.history.history_cmd(idx).await);
+ Some(crate::action::Action::UpdateFocus(
+ crate::action::Focus::Readline,
+ ))
+ } else {
+ None
+ }
+ }
_ => None,
}
}