parse control, ignore ^C

This commit is contained in:
Raptorox 2025-10-10 15:16:57 +02:00
parent 03131fda71
commit 9e9016d9d7
No known key found for this signature in database
GPG key ID: 8B3556FC3ED1F6D8
2 changed files with 13 additions and 0 deletions

View file

@ -5,6 +5,7 @@ pub enum Key {
Char(char),
Enter,
Backspace,
Ctrl(char),
Escape,
ArrowUp,
ArrowDown,
@ -32,6 +33,9 @@ impl From<u8> for Key {
_ => Key::Unknown(vec![27, buf[0], buf[1]]),
}
}
1..=26 => {
Key::Ctrl((byte as u8 + b'a' - 1) as char)
}
char if char.is_ascii() => Key::Char(byte as char),
byte => Key::Unknown(vec![byte]),
}

View file

@ -44,6 +44,15 @@ fn handle_input(stdin: &mut Stdin, stdout: &mut Stdout, data: &mut Data) -> io::
let key = Key::from(buffer[0]);
match key {
Key::Ctrl('c') => {
}
Key::Ctrl('d') => {
break;
}
Key::Ctrl(_) => {
}
Key::Enter => {
data.add_to_hist(input.clone());
write!(stdout, "\r\n")?;