diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-03-30 13:01:32 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-03-30 13:01:52 +0300 |
| commit | 741fbbe8b30774247f8a68831d8df469672e1947 (patch) | |
| tree | 608afe0a8415ea1a3ee2035f809795dc09809dfc /src/input/model.rs | |
| parent | ca14500717864b1c9b1885cbbc6a451a19b9caf8 (diff) | |
refactor: split terminal keyboard protocol module
Diffstat (limited to 'src/input/model.rs')
| -rw-r--r-- | src/input/model.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/input/model.rs b/src/input/model.rs new file mode 100644 index 00000000..31c521e8 --- /dev/null +++ b/src/input/model.rs @@ -0,0 +1,57 @@ +use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct TerminalKey { + pub code: KeyCode, + pub modifiers: KeyModifiers, + pub kind: crossterm::event::KeyEventKind, + pub shifted_codepoint: Option<u32>, +} + +impl TerminalKey { + pub fn new(code: KeyCode, modifiers: KeyModifiers) -> Self { + Self { + code, + modifiers, + kind: crossterm::event::KeyEventKind::Press, + shifted_codepoint: None, + } + } + + pub fn with_kind(mut self, kind: crossterm::event::KeyEventKind) -> Self { + self.kind = kind; + self + } + + #[allow(dead_code)] // Reserved for the upcoming raw input parser to preserve shifted/base key pairs. + pub fn with_shifted_codepoint(mut self, shifted_codepoint: u32) -> Self { + self.shifted_codepoint = Some(shifted_codepoint); + self + } + + pub fn as_key_event(self) -> KeyEvent { + KeyEvent::new_with_kind(self.code, self.modifiers, self.kind) + } +} + +impl From<KeyEvent> for TerminalKey { + fn from(value: KeyEvent) -> Self { + Self::new(value.code, value.modifiers).with_kind(value.kind) + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum KeyboardProtocol { + Legacy, + Kitty { flags: u16 }, +} + +impl KeyboardProtocol { + pub fn from_kitty_flags(flags: u16) -> Self { + if flags == 0 { + Self::Legacy + } else { + Self::Kitty { flags } + } + } +} |
