class

Phosphor::KeyEvent

Inherits Phosphor::Event < Reference < Object

A single keypress received from the terminal.

Widgets pattern-match on key to translate keypresses into application Msg values. Construct via KeyEvent.from_raw(bytes) in production; construct directly with a Key constant in specs.

Constants

ESCAPE_SEQUENCES = {"\e[A" => Key::Up, "\e[B" => Key::Down, "\e[C" => Key::Right, "\e[D" => Key::Left, "\e[H" => Key::Home, "\e[1~" => Key::Home, "\e[F" => Key::End, "\e[4~" => Key::End, "\e[5~" => Key::PageUp, "\e[6~" => Key::PageDown, "\e[3~" => Key::Delete, "\e[Z" => Key::ShiftTab, "\eOP" => Key::F1, "\eOQ" => Key::F2, "\eOR" => Key::F3, "\eOS" => Key::F4, "\e[15~" => Key::F5, "\e[17~" => Key::F6, "\e[18~" => Key::F7, "\e[19~" => Key::F8, "\e[20~" => Key::F9, "\e[21~" => Key::F10, "\e[23~" => Key::F11, "\e[24~" => Key::F12, "\e[23;2~" => Key::ShiftF11}

VT100/xterm escape sequence → Key table. Codes 16 and 22 are unassigned in the standard (hence the gaps in F5-F12). Home and End have two common encodings each; both are listed.

Constructors

from_raw(bytes : Bytes) : KeyEvent

Parses raw stdin bytes into a KeyEvent.

Single bytes are mapped directly to their Key constant, or to a KeyChar for any other printable ASCII byte (0x20-0x7E). Multi-byte sequences are matched against the standard VT100/xterm escape table. Unrecognised sequences produce Key::Unknown — callers decide whether to surface or discard.

Source
new(key : KeyKind)
Source

Instance methods