Skip to content

Commit

Permalink
Add support for combining some modifier keys (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartoffelsaft authored Dec 28, 2020
1 parent 0797441 commit 744ec05
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/event/sys/unix/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}),
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 744ec05

Please sign in to comment.