Skip to main content

key_to_bytes

Function key_to_bytes 

Source
pub fn key_to_bytes(key: KeyEvent) -> Vec<u8> 
Expand description

Translate a crossterm KeyEvent into the raw byte sequence the remote device sees. Returns an empty Vec for events that do not correspond to a byte on the wire (e.g. modifier-only presses).

Semantics:

  • Ctrl-<letter>0x01..=0x1a (e.g. Ctrl-A → 0x01).
  • Plain KeyCode::Char → UTF-8 encoding of that character.
  • KeyCode::EnterCR (0x0d), matching picocom’s default “send CR on Enter” behaviour. Line-ending translation (CR → CRLF etc.) is the mapper’s job (Issue #8), not ours.
  • KeyCode::TabHT (0x09).
  • KeyCode::BackspaceDEL (0x7f), again matching picocom.
  • KeyCode::EscESC (0x1b).
  • Anything else (arrows, function keys, modifier-only) returns an empty Vec. T14+ can grow CSI sequences if a real use case surfaces.