pub fn terminal_key_bytes(key: &KeyEvent) -> Option<Vec<u8>>Expand description
Encodes a pressed key using default terminal modes.
Supported named keys are Enter, Backspace, Tab, Escape, four arrows,
Home/End, PageUp/PageDown, Delete, Insert, and Space. Character/dead-key text
is UTF-8. Ctrl combinations are limited to C, D, L, and Z. Alt prefixes one
Escape byte unless the base sequence already begins with Escape. Releases and
unsupported keys return None; repeat presses are encoded normally.
ยงExamples
use ailloli_ui_core::event::{Key, KeyEvent, KeyState, Modifiers, NamedKey};
use ailloli_ui_widgets::controls::terminal_key_bytes;
let key = KeyEvent {
state: KeyState::Pressed,
key: Key::Named(NamedKey::Enter),
modifiers: Modifiers::default(),
repeat: false,
pointer_pos: None,
text: None,
};
assert_eq!(terminal_key_bytes(&key), Some(b"\r".to_vec()));