Function terminal_key_bytes_with_modes

Source
pub fn terminal_key_bytes_with_modes(
    key: &KeyEvent,
    modes: &TerminalModes,
) -> Option<Vec<u8>>
Expand description

Encodes a pressed key while honoring terminal application-cursor mode.

When application_cursor is enabled, arrows and Home/End use SS3 sequences; all other mappings match terminal_key_bytes.

ยงExamples

use ailloli_ui_core::event::{Key, KeyEvent, KeyState, Modifiers, NamedKey};
use ailloli_ui_terminal_core::TerminalModes;
use ailloli_ui_widgets::controls::terminal_key_bytes_with_modes;
let key = KeyEvent {
    state: KeyState::Pressed,
    key: Key::Named(NamedKey::ArrowUp),
    modifiers: Modifiers::default(),
    repeat: false,
    pointer_pos: None,
    text: None,
};
let modes = TerminalModes { application_cursor: true, ..TerminalModes::default() };
assert_eq!(terminal_key_bytes_with_modes(&key, &modes), Some(b"\x1bOA".to_vec()));