1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Cleanroom Rust port of upstream Go source file: `keyboard.go`
//! Upstream Target Tag / Version: `v2.0.8`
//!
//! <public-docs>
//! # Keyboard Enhancements
//!
//! Kitty keyboard protocol enhancement message structures and capability queries.
//! </public-docs>
/// Bitmask constants matching Kitty keyboard protocol enhancements.
pub const KITTY_REPORT_EVENT_TYPES: i32 = 1 << 0;
/// Report alternate keys capability flag.
pub const KITTY_REPORT_ALTERNATE_KEYS: i32 = 1 << 1;
/// Report all keys as escape codes capability flag.
pub const KITTY_REPORT_ALL_KEYS_AS_ESCAPE_CODES: i32 = 1 << 2;
/// Report associated keys capability flag.
pub const KITTY_REPORT_ASSOCIATED_KEYS: i32 = 1 << 3;
/// KeyboardEnhancements struct matching tea.KeyboardEnhancements in v2.0.8.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct KeyboardEnhancements {
/// Report press, release, and repeat events.
pub report_event_types: bool,
/// Report alternate keys.
pub report_alternate_keys: bool,
/// Report all keys as escape codes.
pub report_all_keys_as_escape_codes: bool,
/// Report associated text.
pub report_associated_text: bool,
}
/// KeyboardEnhancementsMsg is a message that gets sent when the terminal
/// supports keyboard enhancements.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct KeyboardEnhancementsMsg {
/// Flags is a bitmask of enabled keyboard enhancement features. A non-zero
/// value indicates that at least we have key disambiguation support.
///
/// Use the `supports_*` methods for the easy way to check individual flags.
pub flags: i32,
}
impl KeyboardEnhancementsMsg {
/// SupportsKeyDisambiguation returns whether the terminal supports key
/// disambiguation (e.g., distinguishing between different modifier keys).
pub fn supports_key_disambiguation(&self) -> bool {
self.flags > 0
}
/// SupportsEventTypes returns whether the terminal supports reporting
/// different types of key events (press, release, and repeat).
pub fn supports_event_types(&self) -> bool {
(self.flags & KITTY_REPORT_EVENT_TYPES) != 0
}
/// SupportsAlternateKeys returns whether the terminal supports reporting
/// alternate key codes.
pub fn supports_alternate_keys(&self) -> bool {
(self.flags & KITTY_REPORT_ALTERNATE_KEYS) != 0
}
/// SupportsAllKeysAsEscapeCodes returns whether the terminal supports
/// reporting all keys as escape codes.
pub fn supports_all_keys_as_escape_codes(&self) -> bool {
(self.flags & KITTY_REPORT_ALL_KEYS_AS_ESCAPE_CODES) != 0
}
/// SupportsAssociatedText returns whether the terminal supports reporting
/// associated text with key events.
pub fn supports_associated_text(&self) -> bool {
(self.flags & KITTY_REPORT_ASSOCIATED_KEYS) != 0
}
}