Add support for combining some modifier keys (#518)

This commit is contained in:
Kartoffelsaft 2020-12-28 00:59:44 -08:00 committed by GitHub
parent 0797441893
commit 744ec05f19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,12 +57,16 @@ pub(crate) fn parse_event(buffer: &[u8], input_available: bool) -> Result<Option
}
b'[' => parse_csi(buffer),
b'\x1B' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Esc.into())))),
_ => parse_utf8_char(&buffer[1..]).map(|maybe_char| {
maybe_char
.map(KeyCode::Char)
.map(|code| KeyEvent::new(code, KeyModifiers::ALT))
.map(Event::Key)
.map(InternalEvent::Event)
_ => parse_event(&buffer[1..], input_available).map(|event_option| {
event_option.map(|event| {
if let InternalEvent::Event(Event::Key(key_event)) = event {
let mut alt_key_event = key_event;
alt_key_event.modifiers |= KeyModifiers::ALT;
InternalEvent::Event(Event::Key(alt_key_event))
} else {
event
}
})
}),
}
}
@ -491,6 +495,28 @@ mod tests {
);
}
#[test]
fn test_alt_shift() {
assert_eq!(
parse_event(b"\x1BH", false).unwrap(),
Some(InternalEvent::Event(Event::Key(KeyEvent::new(
KeyCode::Char('H'),
KeyModifiers::ALT | KeyModifiers::SHIFT
)))),
);
}
#[test]
fn test_alt_ctrl() {
assert_eq!(
parse_event(b"\x1B\x14", false).unwrap(),
Some(InternalEvent::Event(Event::Key(KeyEvent::new(
KeyCode::Char('t'),
KeyModifiers::ALT | KeyModifiers::CONTROL
)))),
);
}
#[test]
fn test_parse_event_subsequent_calls() {
// The main purpose of this test is to check if we're passing