sigildocs

(sigil tui event)

(sigil tui event) - Terminal input event parsing

Parses raw terminal input bytes into structured events. Handles ESC sequences (CSI), SGR mouse reports, Ctrl codes, function keys, and UTF-8 multi-byte characters.

Event representation (tagged lists):

(key #\a)                ;; printable character
(key #\a ctrl)           ;; Ctrl+A
(key #\a alt)            ;; Alt+A (ESC prefix)
(key up)                 ;; arrow key
(key f1)                 ;; function key
(mouse press 10 5)       ;; mouse button press at col 10, row 5
(resize 80 24)           ;; terminal resized

Exports

key-event?procedure

Check if an event is a key event.

mouse-event?procedure

Check if an event is a mouse event.

resize-event?procedure

Check if an event is a resize event.

key-event-keyprocedure

Get the key from a key event (char or symbol).

Get the modifier from a key event, or #f if none.

Get the type from a mouse event (press, release, scroll-up, scroll-down).

Get the column from a mouse event.

Get the row from a mouse event.

parse-inputprocedure

Parse raw terminal input bytes into a list of events.

Takes a parser state (for buffering incomplete sequences) and a bytevector of raw input. Returns a list of events.

(define state (make-parser-state))
(define events (parse-input state #u8(97)))  ;; => ((key #\a))