mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-15 06:24:01 +00:00
fish_key_reader: minimize logic following recent changes
This commit is contained in:
parent
405c9c6aaf
commit
1c41bcd1a4
1 changed files with 3 additions and 24 deletions
|
@ -82,30 +82,10 @@ fn sequence_name(recent_chars: &mut Vec<u8>, c: char) -> Option<WString> {
|
||||||
input_terminfo_get_name(&str2wcstring(recent_chars))
|
input_terminfo_get_name(&str2wcstring(recent_chars))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn output_bind_command(bind_chars: &mut Vec<(Key, WString)>) {
|
|
||||||
if !bind_chars.is_empty() {
|
|
||||||
printf!("bind ");
|
|
||||||
for (key, _seq) in &*bind_chars {
|
|
||||||
printf!("%s", key);
|
|
||||||
}
|
|
||||||
printf!(" 'do something'\n");
|
|
||||||
bind_chars.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn output_matching_key_name(recent_chars: &mut Vec<u8>, c: char) -> bool {
|
|
||||||
if let Some(name) = sequence_name(recent_chars, c) {
|
|
||||||
printf!("bind -k %ls 'do something'\n", name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Process the characters we receive as the user presses keys.
|
/// Process the characters we receive as the user presses keys.
|
||||||
fn process_input(continuous_mode: bool) -> i32 {
|
fn process_input(continuous_mode: bool) -> i32 {
|
||||||
let mut first_char_seen = false;
|
let mut first_char_seen = false;
|
||||||
let mut queue = InputEventQueue::new(STDIN_FILENO);
|
let mut queue = InputEventQueue::new(STDIN_FILENO);
|
||||||
let mut bind_chars = vec![];
|
|
||||||
let mut recent_chars1 = vec![];
|
let mut recent_chars1 = vec![];
|
||||||
let mut recent_chars2 = vec![];
|
let mut recent_chars2 = vec![];
|
||||||
eprintf!("Press a key:\n");
|
eprintf!("Press a key:\n");
|
||||||
|
@ -120,10 +100,9 @@ fn process_input(continuous_mode: bool) -> i32 {
|
||||||
if c == key::Invalid {
|
if c == key::Invalid {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
bind_chars.push((kevt.key, kevt.seq));
|
printf!("bind %s 'do something'\n", kevt.key);
|
||||||
output_bind_command(&mut bind_chars);
|
if let Some(name) = sequence_name(&mut recent_chars1, c) {
|
||||||
if output_matching_key_name(&mut recent_chars1, c) {
|
printf!("bind -k %ls 'do something'\n", name);
|
||||||
output_bind_command(&mut bind_chars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if continuous_mode && should_exit(&mut recent_chars2, kevt.key) {
|
if continuous_mode && should_exit(&mut recent_chars2, kevt.key) {
|
||||||
|
|
Loading…
Reference in a new issue