keyfork-prompt: add KEYFORK_PROMPT_MNEMONIC_MODE=steel #32

Manually merged
ryan merged 1 commits from ryan/keyfork-prompt/steel into main 2024-02-23 03:22:37 +00:00
1 changed files with 23 additions and 3 deletions
Showing only changes of commit f206cd5db1 - Show all commits

View File

@ -122,9 +122,15 @@ where
W: Write + AsRawFd, W: Write + AsRawFd,
{ {
fn drop(&mut self) { fn drop(&mut self) {
self.write.execute(DisableBracketedPaste).expect(bug!("can't restore bracketed paste")); self.write
self.write.execute(LeaveAlternateScreen).expect(bug!("can't leave alternate screen")); .execute(DisableBracketedPaste)
self.terminal.disable_raw_mode().expect(bug!("can't disable raw mode")); .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) => { KeyCode::Char(c) => {
input.push(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(' ');
}
}
}
}
}
} }
_ => (), _ => (),
}, },