keyfork-prompt: add KEYFORK_PROMPT_MNEMONIC_MODE=steel

This commit is contained in:
Ryan Heywood 2024-02-21 02:50:57 -05:00
parent 1699975b57
commit f206cd5db1
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 23 additions and 3 deletions

View File

@ -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(' ');
}
}
}
}
}
}
_ => (),
},