@@ -11,15 +11,17 @@ This specification describes Clayterm's terminal input parsing surface: the API
1111for decoding raw terminal byte sequences into structured events.
1212
1313Input parsing is architecturally independent from rendering (see
14- [ Renderer Specification] ( renderer-spec.md ) , INV-8 ). The two concerns share a
14+ [ Renderer Specification] ( renderer-spec.md ) , INV-7 ). The two concerns share a
1515compiled WASM binary for loading efficiency, but neither depends on the other's
16- state, types, or API surface.
16+ state, types, or API surface. Both consume the shared capability layer defined
17+ in the [ Terminfo Specification] ( terminfo-spec.md ) ; the input parser is
18+ additionally that layer's runtime write path (see Section 6).
1719
18- This specification is currently non-normative. The input API has clear design
19- intent but has undergone more revision than the rendering core and faces known
20- upcoming forces that will reshape it (Kitty progressive enhancement field
21- surfacing, terminfo binary parsing ). It is written to document the current
22- surface and guide future stabilization.
20+ This specification is currently non-normative except where noted . The input API
21+ has clear design intent but has undergone more revision than the rendering core
22+ and faces known upcoming forces that will reshape it (Kitty progressive
23+ enhancement field surfacing ). It is written to document the current surface and
24+ guide future stabilization.
2325
2426---
2527
@@ -31,6 +33,8 @@ surface and guide future stabilization.
3133- The scan API and its return type
3234- The ` InputEvent ` discriminated union and its variants
3335- The ESC timeout resolution model
36+ - Terminfo integration: key sequence loading and capability query response
37+ recognition (Section 6, normative)
3438
3539### Out of scope
3640
@@ -74,8 +78,11 @@ Options:
7478 responsiveness (lower values) and correct disambiguation of ESC-prefixed
7579 sequences (higher values).
7680
77- - ** ` terminfo ` ** — A ` Uint8Array ` of raw terminfo binary. Accepted but C-side
78- parsing is not yet implemented.
81+ - ** ` detection ` ** — A ` Detection ` value from ` detectTerminal() ` (see
82+ [ Terminfo Specification] ( terminfo-spec.md ) §10.1). Terminal-specific key
83+ sequences from ` detection.keys ` are loaded into the parser's escape sequence
84+ trie at initialization (Section 6.1). When omitted, the parser uses built-in
85+ xterm default sequences.
7986
8087### 4.2 Scan
8188
@@ -135,7 +142,45 @@ has already been extended with fields that are not yet mapped to the TS types).
135142
136143---
137144
138- ## 6. Deferred / Future Areas
145+ ## 6. Terminfo Integration
146+
147+ _ This section is normative. It defines the input parser's two roles in the
148+ capability layer specified by the [ Terminfo Specification] ( terminfo-spec.md ) ._
149+
150+ ### 6.1 Key sequences from terminfo
151+
152+ When given a ` detection ` value whose ` keys ` field is present, the parser MUST
153+ load the terminal's ` key_* ` string capabilities into its escape sequence trie at
154+ initialization, before any scan. Terminfo-supplied sequences take precedence
155+ over the built-in xterm defaults when they conflict; defaults remain registered
156+ for sequences the terminfo entry does not define.
157+
158+ The key capabilities consumed are the ` key_* ` string range mapped to existing
159+ ` KEY_* ` codes: arrows (` kcuu1 ` , ` kcud1 ` , ` kcub1 ` , ` kcuf1 ` ), function keys
160+ (` kf1 ` –` kf12 ` ), editing keys (` khome ` , ` kend ` , ` kich1 ` , ` kdch1 ` , ` kpp ` , ` knp ` ),
161+ and backtab (` kcbt ` ). Key capabilities with no corresponding ` KEY_* ` code are
162+ ignored.
163+
164+ ### 6.2 Query response recognition
165+
166+ During a normal scan — with responses potentially interleaved with user input —
167+ the parser MUST recognize and consume the probe responses listed in Terminfo
168+ Specification §9.1: OSC 10/11/12 theme color reports, OSC 21 kitty color
169+ reports, OSC 22 pointer shape reports, XTGETTCAP DCS replies, DECRPM mode-2026
170+ reports, kitty keyboard flag reports, kitty graphics APC replies, and the DA1
171+ device attributes report.
172+
173+ For each recognized response the parser MUST emit a ` CapabilityEvent ` in the
174+ ` scan() ` return value, per Terminfo Specification §6.3 and TINV-6. Responses are
175+ consumed silently: they MUST NOT surface as ` InputEvent ` s, and bytes belonging
176+ to a recognized response MUST NOT leak into adjacent events.
177+
178+ When the parser is standalone (no ` detection ` ), responses are still recognized
179+ and consumed so stray replies never corrupt the event stream.
180+
181+ ---
182+
183+ ## 7. Deferred / Future Areas
139184
140185_ These topics are explicitly excluded from this specification. Their omission is
141186intentional, not an oversight._
@@ -144,25 +189,6 @@ intentional, not an oversight._
144189struct has been extended for progressive enhancement fields. The TypeScript
145190event types have not been updated to surface them.
146191
147- ** Terminfo binary parsing.** The input API accepts a ` terminfo ` option, but
148- C-side parsing is not implemented.
149-
150192** Whether input parsing should be a separate package.** Architecturally
151193independent from the renderer but currently co-located. The distribution
152194decision is open.
153-
154- ---
155-
156- ## Open Decisions
157-
158- 1 . ** What are the normative Kitty progressive enhancement event types?** The
159- C-side struct has been extended. The TypeScript types have not been updated.
160- This specification does not attempt to predict the final shapes.
161-
162- 2 . ** Should the input API be a separate package?** It is architecturally
163- independent from the renderer (INV-8) but currently co-located in the same
164- module.
165-
166- 3 . ** Is the input API ready for normative specification?** The API has clear
167- design ownership but has undergone more revision than the rendering core.
168- This specification documents the current surface without freezing it.
0 commit comments