From f206cd5db113dff1bff2212951140b38b089225c Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 21 Feb 2024 02:50:57 -0500 Subject: [PATCH] keyfork-prompt: add KEYFORK_PROMPT_MNEMONIC_MODE=steel --- crates/util/keyfork-prompt/src/terminal.rs | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/util/keyfork-prompt/src/terminal.rs b/crates/util/keyfork-prompt/src/terminal.rs index 2cf75cc..e431215 100644 --- a/crates/util/keyfork-prompt/src/terminal.rs +++ b/crates/util/keyfork-prompt/src/terminal.rs @@ -122,9 +122,15 @@ where W: Write + AsRawFd, { fn drop(&mut self) { - self.write.execute(DisableBracketedPaste).expect(bug!("can't restore bracketed paste")); - self.write.execute(LeaveAlternateScreen).expect(bug!("can't leave alternate screen")); - self.terminal.disable_raw_mode().expect(bug!("can't disable raw mode")); + self.write + .execute(DisableBracketedPaste) + .expect(bug!("can't restore bracketed paste")); + self.write + .execute(LeaveAlternateScreen) + .expect(bug!("can't leave alternate screen")); + self.terminal + .disable_raw_mode() + .expect(bug!("can't disable raw mode")); } } @@ -288,6 +294,20 @@ where } KeyCode::Char(c) => { input.push(c); + let entry_mode = std::env::var("KEYFORK_PROMPT_MNEMONIC_MODE"); + if entry_mode.is_ok_and(|mode| mode.to_ascii_lowercase() == "steel") { + let word = input.split_whitespace().next_back().map(ToOwned::to_owned); + if let Some(steel_word) = word { + if steel_word.len() >= 4 { + for word in words.iter().filter(|word| word.len() >= 4) { + if word[..4] == steel_word { + input.push_str(&word[4..]); + input.push(' '); + } + } + } + } + } } _ => (), }, -- 2.40.1