Skip to content

feat: term.update() folds CapabilityEvents into runtime capabilities - #133

Open
natemoo-re wants to merge 4 commits into
feat/input-probe-eventsfrom
feat/term-capability-sink
Open

natemoo-re wants to merge 4 commits into
feat/input-probe-eventsfrom
feat/term-capability-sink

Conversation

@natemoo-re

@natemoo-re natemoo-re commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

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 }, any InputEvent, or an array of them; it returns bytes to write (empty for now)
  • createTerm({ terminfo }) seeds the renderer from a TerminalInfo; term.capabilities exposes the current snapshot (256-color baseline when omitted)
  • validated() forwards the new capabilities getter
  • Changeset covers detectTerminal/TerminalInfo, the createTerm option, and the update({ events }) → update(events) break
  • Out of scope: no change to rendered bytes yet; first consumer is color encoding modes (💡 Color-encoding modes (16-color / 256-color) derived from terminfo #60), other protocol follow-ups in Track terminfo capability follow-ups #129

Split from #106 for reviewability; #106 closes when this stack lands.

@natemoo-re
natemoo-re added this pull request to stack #134 September 19, 2026 04:29
@bombshell-cooper

bombshell-cooper Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Changeset suggestion

The 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 @@
---

@bombshell-cooper bombshell-cooper Bot Sep 19, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
```

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Size Increased — +9.8 KB

121.4 KB unpacked

@pkg-pr-new

pkg-pr-new Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@bomb.sh/tty@133

commit: eb3b262

@natemoo-re natemoo-re changed the title feat: term.update() folds CapabilityEvents into runtime capabilities (renderer-spec §7.7, §8.6) feat: term.update() folds CapabilityEvents into runtime capabilities Sep 19, 2026
@codspeed

codspeed Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 10 untouched benchmarks


Comparing feat/term-capability-sink (eb3b262) with feat/input-probe-events (5081cb4)1

Open in CodSpeed

Footnotes

  1. No successful run was found on feat/input-probe-events (0d1f019) during the generation of this report, so 3527203 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@natemoo-re
natemoo-re force-pushed the feat/term-capability-sink branch from c64972d to d5be56e Compare September 30, 2026 01:50
natemoo-re added a commit that referenced this pull request Sep 30, 2026
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.
@natemoo-re
natemoo-re force-pushed the feat/term-capability-sink branch from 42fa5a4 to f124b5d Compare September 30, 2026 02:01
@natemoo-re
natemoo-re force-pushed the feat/term-capability-sink branch from f124b5d to 5be02ae Compare September 30, 2026 02:03
@natemoo-re
natemoo-re force-pushed the feat/term-capability-sink branch from 5be02ae to 34fca15 Compare September 30, 2026 15:11
@natemoo-re
natemoo-re marked this pull request as ready for review September 30, 2026 15:12
@natemoo-re
natemoo-re force-pushed the feat/term-capability-sink branch 3 times, most recently from 564ad65 to 7322ee4 Compare October 6, 2026 03:03
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.
@natemoo-re
natemoo-re force-pushed the feat/term-capability-sink branch from 7322ee4 to eb3b262 Compare October 6, 2026 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant