Termisu::Input::Parser
Inherits Reference / Object
Input parser for terminal escape sequences.
Parses raw terminal input into structured Event objects. Supports CSI sequences (arrows, function keys, nav), SS3 sequences, Alt+key combinations, Ctrl+key combinations, and mouse events.
Example:
parser = Termisu::Input::Parser.new(reader)
if event = parser.poll_event(1000)
puts "Got event: #{event}"
end
Constants
CSI final character to Key mapping.
Timeout in milliseconds to distinguish ESC key from escape sequences. 50ms matches termbox/tcell behavior.
Kitty protocol codepoint to Key mapping for special keys. These codepoints are specific to the Kitty keyboard protocol.
Linux console function keys use \e[[A through \e[[E.
Maximum escape sequence length before giving up.
Mouse protocol bit mask for motion events (bit 5). When set, indicates mouse moved while button was held.
The bytes that follow ESC in the end marker, matched literally.
Inside a paste the terminator is found by comparing raw bytes, never by
parsing an escape sequence. Two ways the parsing route loses it: the fd can
run dry at the marker's ESC and the rest arrive after ESCAPE_TIMEOUT_MS (the
ESC then resolves as a bare Escape and [201~ lands as text), and paste
CONTENT ending in a truncated escape can swallow the marker's ESC into its
own Alt-key or CSI-parameter branch. Both wedge a consumer that tracks
PasteStart/PasteEnd as a boolean, since the mode never closes.
How long to wait for the rest of the end marker once its ESC has arrived.
Deliberately not ESCAPE_TIMEOUT_MS: that value exists to tell a lone Escape KEYPRESS from a sequence, a distinction a paste has already settled — the terminal opened the bracket and owes us the close. It only has to outlast scheduling jitter on the tail of a transfer (ssh/mosh, a loaded machine), which 50ms does not. Bounded rather than infinite so a terminal that dies mid-paste degrades to delivering the bytes as content instead of hanging.
Bracketed paste boundary codes, also delivered as \e[N~ sequences.
Kept out of TILDE_KEYS because they are not keystrokes: they only mark
where a paste begins and ends. A terminal sends them exclusively while DEC
private mode 2004 is on (see Terminal#enable_bracketed_paste), which is
why an application that never enables the mode cannot observe them.
SS3 final character to Key mapping (\eO...).
Tilde sequence code to Key mapping (\e[N~ format).
Maps numeric codes from CSI tilde sequences to keys. Codes 1-8 are navigation keys, 11-24 are function keys F1-F12. Codes 25-34 are extended function keys F13-F20 (rarely used).
Note: Some codes are skipped (9-10, 16, 22, 27, 30) for historical terminal compatibility reasons. Codes 1/7 and 4/8 are duplicates (Home/End) because different terminals use different codes.
Reference: XTerm ctlseqs, VT220 sequences.
Constructors
Instance methods
Polls for an input event with optional timeout.
timeout_ms- Timeout in milliseconds (-1 for blocking)
Returns an Event or nil if timeout/no data.