Module: reefvision.input
Source: ./reefvision/input.reef
Overview
reefvision.input — pure byte stream → KeyEvent / Event decoder
Design §9.1 + Phase 2 SGR mouse (CSI < Pb ; Px ; Py M/m). No TTY: feed canned bytes in unit tests.
Pure decoder: no curses, no host TTY reads in this module.
Types
KeyDecoder
Fields:
| Name | Type |
|---|---|
buf |
[int] |
len |
int |
in_paste |
bool |
paste_buf |
[int] |
paste_len |
int |
has_paste |
bool |
paste_text |
string |
ParseOne
Result of trying to parse one input unit at buffer head. consumed == 0 means incomplete; is_mouse selects ke vs me; skip = no event.
Fields:
| Name | Type |
|---|---|
ke |
event.KeyEvent |
me |
event.MouseEvent |
is_mouse |
bool |
skip |
bool |
consumed |
int |
incomplete |
bool |
Functions
fn decoder_create(): KeyDecoder
fn decoder_pending(dec: KeyDecoder): int
fn byte_of_char(c: char): int
Byte 0..255 from a char (handle signed char hosts).
fn bytes_of(b0: int): string
fn bytes_of2(b0: int, b1: int): string
fn bytes_of3(b0: int, b1: int, b2: int): string
fn bytes_of4(b0: int, b1: int, b2: int, b3: int): string
fn bytes_concat(a: string, b: string): string
fn bytes_esc(suffix: string): string
ESC (0x1b) + suffix
fn bytes_csi(body: string): string
CSI: ESC [ body (body e.g. "A", "3~", "1;2A")
fn bytes_ss3(final_ch: int): string
SS3: ESC O final (final is ASCII letter code, e.g. 80='P' for F1)
fn fkey_from_num(n: int): event.KeyCode
fn arrow_from_letter(c: int): event.KeyCode
fn parse_fail_incomplete(): ParseOne
fn parse_ok(ke: event.KeyEvent, n: int): ParseOne
fn parse_ok_skip(n: int): ParseOne
fn parse_ok_mouse(me: event.MouseEvent, n: int): ParseOne
fn sgr_button_from_pb(pb: int, out_shift: [bool], out_alt: [bool], out_ctrl: [bool], out_motion: [bool]): event.MouseButton
Decode xterm Pb: button + 4shift + 8alt + 16ctrl + 32motion (flags are powers of two; peel with /2 tests).
fn parse_sgr_mouse(dec: KeyDecoder, flush: bool): ParseOne
SGR mouse: ESC [ < Pb ; Px ; Py M|m (coords 1-based → store 0-based)
fn parse_csi(dec: KeyDecoder, flush: bool): ParseOne
CSI after ESC [: params ; params final Examples: [A [3~ [1;2A [15~ [Z and mouse [< …
fn parse_ss3(dec: KeyDecoder, flush: bool): ParseOne
SS3 after ESC O: single final letter
fn parse_escape(dec: KeyDecoder, flush: bool): ParseOne
fn utf8_lead_len(b: int): int
UTF-8 lead → expected length
fn parse_utf8(dec: KeyDecoder, flush: bool): ParseOne
fn parse_paste_body(dec: KeyDecoder, flush: bool): ParseOne
While in bracketed paste: accumulate until ESC [ 201 ~
fn paste_bytes_to_string(dec: KeyDecoder): string
fn decoder_has_paste(dec: KeyDecoder): bool
fn decoder_take_paste(dec: KeyDecoder): string
fn parse_one(dec: KeyDecoder, flush: bool): ParseOne
fn decoder_poll(dec: KeyDecoder, out: [event.KeyEvent], max_out: int): int
fn decoder_flush(dec: KeyDecoder, out: [event.KeyEvent], max_out: int): int
fn decode_all(data: string, out: [event.KeyEvent], max_out: int): int
fn parse_to_event(r: ParseOne): event.Event
fn decoder_poll_events(dec: KeyDecoder, out: [event.Event], max_out: int): int
fn decoder_flush_events(dec: KeyDecoder, out: [event.Event], max_out: int): int
fn decode_all_events(data: string, out: [event.Event], max_out: int): int
fn event_from_key(ke: event.KeyEvent): event.Event
KeyEvent → Event. Ctrl-C (ctrl + 'C') becomes Quit for app convenience.
fn event_from_key_raw(ke: event.KeyEvent): event.Event
Always Key event (no Ctrl-C promotion).
Procedures
proc decoder_clear(dec: KeyDecoder)
proc decoder_feed(dec: KeyDecoder, data: string)
proc drop_front(dec: KeyDecoder, n: int)
Drop first n bytes from the pending buffer.
proc apply_mod_param(ke: event.KeyEvent, modp: int)
Parse CSI modifier param (xterm): 1=none, 2=shift, 3=alt, 4=shift+alt, 5=ctrl, 6=shift+ctrl, 7=alt+ctrl, 8=shift+alt+ctrl.
Generated by reefc doc