|
2 | 2 | "@bomb.sh/tty": minor |
3 | 3 | --- |
4 | 4 |
|
5 | | -Adds `detectTerminal`, `Capabilities`, `Detection`, `CapabilityEvent`, and `KeyTable` to the public API. |
| 5 | +Adds `detectTerminal()`, `TerminalInfo`, `Capabilities`, `DetectOptions`, `KeyTable`, and `MAX_TERMINFO_ENTRY` to the public API, and a `terminfo` option to `createTerm`. |
6 | 6 |
|
7 | | -`detectTerminal()` reads a compiled terminfo binary (from disk or injected bytes), applies environment evidence (`COLORTERM`), and returns a frozen `Detection` carrying static `Capabilities`, a `probe` query batch to write to stdout, and opaque `keys` bytes for the input parser. |
| 7 | +`detectTerminal()` reads the compiled terminfo entry for the current terminal (from the ncurses search path, or from bytes passed as `entry`), applies environment evidence (`COLORTERM`), and resolves a frozen `TerminalInfo` carrying static `capabilities`, a `probe` query batch to write to stdout, and opaque `keys` for the input parser. |
8 | 8 |
|
9 | | -Pass `detection` to `createInput` to seed its escape-sequence trie with terminal-specific `key_*` sequences. Pass capability events from `scan()` to `term.update()` to keep the renderer's runtime capability snapshot current. |
| 9 | +Pass the same `TerminalInfo` as `terminfo` to `createTerm` and `createInput`. `term.capabilities` exposes the renderer's current capability snapshot, seeded from `terminfo.capabilities` (or the 256-color baseline when omitted). |
10 | 10 |
|
11 | | -`scan()` now recognizes probe responses — OSC 10/11/12/21/22, XTGETTCAP, DECRPM mode 2026, kitty keyboard, kitty graphics APC, and the DA1 fence — and surfaces them as `CapabilityEvent` values interleaved with key and mouse events. Route these to `term.update()`, which returns a `Uint8Array` of bytes to write immediately (empty when no output is needed). |
12 | | - |
13 | | -`InputOptions.terminfo` is replaced by `InputOptions.detection`. Both parsers remain usable without a `Detection`; the 256-color baseline and xterm default key sequences apply when it is omitted. |
| 11 | +**Breaking:** `term.update()` now takes one change or an array of changes — a `{ width, height }` resize or any `InputEvent` — instead of `{ events }`. Capability events from `scan()` are folded into `term.capabilities`; other input events are ignored, so the whole `events` array can be passed through. `update()` returns a `Uint8Array` of bytes to write immediately (empty when there are none). |
14 | 12 |
|
15 | 13 | #### Migration |
16 | 14 |
|
17 | 15 | ```diff |
18 | | --const input = await createInput({ terminfo: await Deno.readFile(terminfoPath) }); |
19 | | -+const detection = await detectTerminal({ env: process.env }); |
20 | | -+const input = await createInput({ detection }); |
21 | | -+process.stdout.write(detection.probe); |
| 16 | +-term.update({ events }); |
| 17 | ++const out = term.update(events); |
| 18 | ++if (out.length) process.stdout.write(out); |
22 | 19 | ``` |
23 | 20 |
|
24 | 21 | ```diff |
25 | | --term.update({ events: resizeEvents }); |
26 | | -+for (const event of input.scan(bytes).events) { |
27 | | -+ if (event.type === "resize" || event.type === "capability") { |
28 | | -+ const out = term.update(event); |
29 | | -+ if (out.length) process.stdout.write(out); |
30 | | -+ } |
31 | | -+} |
| 22 | ++const terminfo = await detectTerminal({ env: process.env }); |
| 23 | ++const term = await createTerm({ width, height, terminfo }); |
| 24 | ++const input = await createInput({ terminfo }); |
| 25 | ++process.stdout.write(terminfo.probe); |
32 | 26 | ``` |
0 commit comments