Add feature cfgs

This commit is contained in:
Timon 2023-04-08 16:15:21 +02:00
parent f580717905
commit 11160d11a0
3 changed files with 18 additions and 6 deletions

View File

@ -256,6 +256,7 @@ bitflags! {
/// Add extra events with [`KeyEvent.kind`] set to [`KeyEventKind::Repeat`] or
/// [`KeyEventKind::Release`] when keys are autorepeated or released.
/// IMPORTANT: Requires feature `event-kind` to be enabled.
#[cfg(feature="event-kind")]
const REPORT_EVENT_TYPES = 0b0000_0010;
// Send [alternate keycodes](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#key-codes)
// in addition to the base keycode. The alternate keycode overrides the base keycode in
@ -614,7 +615,9 @@ bitflags! {
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
pub enum KeyEventKind {
Press,
#[cfg(feature = "event-kind")]
Repeat,
#[cfg(feature = "event-kind")]
Release,
}
@ -650,6 +653,7 @@ pub struct KeyEvent {
/// Additional key modifiers.
pub modifiers: KeyModifiers,
/// Kind of event.
/// By default `KeyEventKind::Press`.
///
/// Only set if:
/// - Unix: [`KeyboardEnhancementFlags::REPORT_EVENT_TYPES`] has been enabled with [`PushKeyboardEnhancementFlags`].

View File

@ -339,6 +339,7 @@ fn parse_modifiers_to_state(mask: u8) -> KeyEventState {
fn parse_key_event_kind(kind: u8) -> KeyEventKind {
match kind {
1 => KeyEventKind::Press,
#[cfg(feature = "event-kind")]
2 => KeyEventKind::Repeat,
#[cfg(feature = "event-kind")]
3 => KeyEventKind::Release,
@ -1341,6 +1342,7 @@ mod tests {
KeyEventKind::Repeat,
)))),
);
#[cfg(feature = "event-kind")]
assert_eq!(
parse_csi_u_encoded_key_code(b"\x1B[97;1:3u").unwrap(),
Some(InternalEvent::Event(Event::Key(KeyEvent::new_with_kind(
@ -1464,6 +1466,7 @@ mod tests {
}
#[test]
#[cfg(feature = "event-kind")]
fn test_parse_csi_special_key_code_with_types() {
assert_eq!(
parse_event(b"\x1B[;1:3B", false).unwrap(),
@ -1484,6 +1487,7 @@ mod tests {
}
#[test]
#[cfg(feature = "event-kind")]
fn test_parse_csi_numbered_escape_code_with_types() {
assert_eq!(
parse_event(b"\x1B[5;1:3~", false).unwrap(),

View File

@ -223,11 +223,13 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option<WindowsKeyEvent>
let kind = if key_event.key_down {
KeyEventKind::Press
} else {
if cfg!(feature = "event-kind") {
#[cfg(feature = "event-kind")]
{
KeyEventKind::Release
} else {
KeyEventKind::Press
}
// Dont register key up event.
#[cfg(not(feature = "event-kind"))]
return None;
};
let key_event = KeyEvent::new_with_kind(key_code, modifiers, kind);
return Some(WindowsKeyEvent::KeyEvent(key_event));
@ -300,11 +302,13 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option<WindowsKeyEvent>
let kind = if key_event.key_down {
KeyEventKind::Press
} else {
if cfg!(feature = "event-kind") {
#[cfg(feature = "event-kind")]
{
KeyEventKind::Release
} else {
KeyEventKind::Press
}
// Dont register key up event.
#[cfg(not(feature = "event-kind"))]
return None;
};
let key_event = KeyEvent::new_with_kind(key_code, modifiers, kind);
return Some(WindowsKeyEvent::KeyEvent(key_event));