Skip to main content

Module input

Module input 

Source
Expand description

Terminal input parsing: a pure bytes-in / events-out state machine.

This is a 1:1 port of ink’s two-stage terminal input pipeline:

  • The (private) segmenter module ports input-parser.ts — the stateful segmentation layer that splits a raw byte stream into opaque key/text byte runs and decoded bracketed-paste payloads, with partial-sequence buffering across chunks. It is an internal detail wrapped by Parser.
  • keypress ports parse-keypress.ts (plus the kitty-protocol decoding from kitty-keyboard.ts) — the pure function that decodes one key sequence into a Key, trying the kitty CSI-u and kitty-enhanced special-key parsers first, then the legacy enquirer-derived table.

There is no I/O and no stream coupling: callers feed bytes and receive a Vec<InputEvent>. This mirrors the future napi push_input(bytes) -> Vec<InputEvent> surface.

§Layering rationale

The two ink files are genuinely different layers and are tested separately upstream: input-parser.ts asserts raw segment strings (['a', "", 'b'], [{paste: 'hello'}]); parse-keypress.ts and the kitty tests assert Key fields. Keeping the segmenter and parse_keypress as distinct, independently testable units lets both upstream test suites be ported verbatim. Parser composes them for the napi consumer.

Re-exports§

pub use keypress::EventType;
pub use keypress::Key;
pub use keypress::parse_keypress;

Modules§

keypress
Port of parse-keypress.ts and the kitty-protocol decoding from kitty-keyboard.ts.

Structs§

Parser
The public input parser: bytes in, InputEvents out, with partial-sequence buffering held across feed calls.

Enums§

InputEvent
A high-level input event handed to the host (the napi push_input consumer). Mirrors ink’s InputEvent (Key from parseKeypress, plus the {paste} arm), composed from the two ported layers.