feat: term.update() folds CapabilityEvents into runtime capabilities - #133
natemoo-re wants to merge 4 commits into
Conversation
Changeset suggestionThe current changeset no longer matches this PR. This review contains a corrected replacement. Why: Changeset package scope does not match the affected packages confidently. Changeset bump does not match the consumer-visible impact. Changeset contains implementation or roadmap noise. Changeset contains unsupported consumer-facing claims. View the proposed changeset---
'@bomb.sh/tty': minor
---
Adds `detectTerminal()`, `TerminalInfo`, `Capabilities`, `DetectOptions`, `KeyTable`, and `MAX_TERMINFO_ENTRY` to the public API, and a `terminfo` option to `createTerm`.
`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.
Pass the returned `TerminalInfo` as `terminfo` to `createTerm` and `createInput`. `term.capabilities` exposes a frozen `RuntimeCapabilities` snapshot seeded from `terminfo.capabilities` (or the 256-color baseline when omitted) and kept current by `update()`.
`term.update()` now accepts one change or an array of changes — a `{ width, height }` resize or any `InputEvent` — instead of an `{ events }` bag. Capability events from `scan()` are folded into `term.capabilities`; other input events are ignored, so the full `events` array can be passed without filtering. `update()` returns a `Uint8Array` of bytes to write immediately (empty when there are none).
#### Migration
```diff
-term.update({ events });
+const out = term.update(events);
+if (out.length) process.stdout.write(out);
```
To enable terminfo-aware rendering:
```diff
+const terminfo = await detectTerminal({ env: process.env });
+const term = await createTerm({ width, height, terminfo });
+const input = await createInput({ terminfo });
+process.stdout.write(terminfo.probe);
```Review this changeset manually If this draft is correct, react with 🚀 and Cooper will commit it to this branch. |
| @@ -0,0 +1,32 @@ | |||
| --- | |||
There was a problem hiding this comment.
Changeset needs revision.
Changeset package scope does not match the affected packages confidently. Changeset bump does not match the consumer-visible impact. Changeset contains implementation or roadmap noise. Changeset contains unsupported consumer-facing claims.
View the proposed replacement
---
'@bomb.sh/tty': minor
---
Adds `detectTerminal()`, `TerminalInfo`, `Capabilities`, `DetectOptions`, `KeyTable`, and `MAX_TERMINFO_ENTRY` to the public API, and a `terminfo` option to `createTerm`.
`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.
Pass the returned `TerminalInfo` as `terminfo` to `createTerm` and `createInput`. `term.capabilities` exposes a frozen `RuntimeCapabilities` snapshot seeded from `terminfo.capabilities` (or the 256-color baseline when omitted) and kept current by `update()`.
`term.update()` now accepts one change or an array of changes — a `{ width, height }` resize or any `InputEvent` — instead of an `{ events }` bag. Capability events from `scan()` are folded into `term.capabilities`; other input events are ignored, so the full `events` array can be passed without filtering. `update()` returns a `Uint8Array` of bytes to write immediately (empty when there are none).
#### Migration
```diff
-term.update({ events });
+const out = term.update(events);
+if (out.length) process.stdout.write(out);
```
To enable terminfo-aware rendering:
```diff
+const terminfo = await detectTerminal({ env: process.env });
+const term = await createTerm({ width, height, terminfo });
+const input = await createInput({ terminfo });
+process.stdout.write(terminfo.probe);
```|
Size Increased — +9.8 KB 121.4 KB unpacked |
commit: |
c64972d to
d5be56e
Compare
Widen Update from { width, height } | CapabilityEvent to
{ width, height } | InputEvent. Events other than resize and capability
are no-op steps, so hosts can pass the full scan() events array without
filtering. Only ResizeEvent carries width/height, so the shapes stay
unambiguous. Matches the implementation in #133.
42fa5a4 to
f124b5d
Compare
f124b5d to
5be02ae
Compare
5be02ae to
34fca15
Compare
564ad65 to
7322ee4
Compare
…(renderer-spec §7.7, §8.6)
The terminfo spec no longer lists applyUpdate as public API; update() is the only entry point, and tests already exercise it through term.update().
The renderer spec now accepts any InputEvent as an Update and requires non-resize, non-capability events to change no state and emit no bytes.
Match createInput: the renderer option is `terminfo`, typed `TerminalInfo`. Adds the first test that seeds createTerm from a detected TerminalInfo (previously untested; test/caps.ts helpers were unused). The stack changeset now covers only what this PR and #131 add — detectTerminal/TerminalInfo, createTerm's option, term.capabilities, and the update() signature change — since #132 carries its own changeset for the input side.
7322ee4 to
eb3b262
Compare
Part 4/4 (final) of the terminfo foundation stack. Requires #132.
term.update()is now the single entry point for resize and capability changes: pass a{ width, height }, anyInputEvent, or an array of them; it returns bytes to write (empty for now)createTerm({ terminfo })seeds the renderer from aTerminalInfo;term.capabilitiesexposes the current snapshot (256-color baseline when omitted)validated()forwards the newcapabilitiesgetterdetectTerminal/TerminalInfo, thecreateTermoption, and theupdate({ events })→update(events)breakSplit from #106 for reviewability; #106 closes when this stack lands.