From a87e03fa707cfdd9779334d4bf177188bb54db5b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 10 Dec 2021 23:07:08 -0500 Subject: space to recall focused command to the readline --- src/history.rs | 4 ++++ src/readline.rs | 5 +++++ src/state.rs | 11 +++++++++++ 3 files changed, 20 insertions(+) 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, } } -- cgit v1.2.3-54-g00ecf