feat: terminfo capability core (parser, detectTerminal) - #131
Draft
natemoo-re wants to merge 5 commits into
Draft
natemoo-re wants to merge 5 commits into
natemoo-re wants to merge 5 commits into
Conversation
natemoo-re
added this pull request to stack #134
September 19, 2026 04:29
Changeset suggestionThis PR changes published packages but has no changeset. View the proposed changeset---
---
Adds `detectTerminal` for resolving terminal capabilities from a compiled terminfo entry and process environment.
`detectTerminal(options?)` reads the terminfo database (respecting `TERMINFO`, `HOME/.terminfo`, and `TERMINFO_DIRS`), parses the binary entry — including the extended capability table (`Tc`, `RGB`, `Su`, `Smulx`) and the 32-bit extended-number format — and returns a frozen `Detection` object:
```ts
import { detectTerminal } from "@bomb.sh/tty";
const { capabilities, probe, keys } = await detectTerminal();
// capabilities.trueColor, .colors, .bce, .altScreen, .styledUnderline …
// write probe to stdout; input.scan() yields CapabilityEvent responses
```
`COLORTERM=truecolor` / `COLORTERM=24bit` upgrades the result even when the terminfo entry does not advertise truecolor. Malformed or missing entries fall back to the xterm-256color baseline without throwing.If this draft is correct, react with 🚀 and Cooper will commit it to this branch. |
|
Size Increased — +8.8 KB 111.6 KB unpacked |
commit: |
This was referenced Sep 19, 2026
cowboyd
reviewed
Sep 28, 2026
The terminfo_parse header comment referenced TINV-3 (progressive enhancement); the all-or-nothing rule is TINV-2 (pure parsing).
natemoo-re
force-pushed
the
feat/terminfo-core
branch
from
September 30, 2026 01:50
e8f7237 to
c3cb6d6
Compare
Match the TERMINFO_ prefix used in terminfo.h and spell capability indices with their full ncurses names (auto_right_margin, eat_newline_glitch, back_color_erase, max_colors, enter_ca_mode) rather than capnames. They stay file-private to terminfo.c since only the parser uses them.
Rename TERMINFO_AM/XENL/BCE to TERMINFO_AUTO_RIGHT_MARGIN, TERMINFO_EAT_NEWLINE_GLITCH, and TERMINFO_BACK_COLOR_ERASE (and the FLAG_* mirrors in terminfo.ts), matching the full ncurses names now used for the parser's capability indices.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 2/4 of the terminfo foundation stack. Requires #130 (spec) to be approved first; kept as a draft until then.
What this adds
src/terminfo.{c,h}: WASM capability core — compiled terminfo binary parsing (legacy011aand extended021eformats), theTermInfostruct (colors, flags, confirmed theme values), and theterminfo_init/parse/grant/confirmexports.terminfo.ts: publicdetectTerminal()API — resolves a terminfo entry (filesystem viaTERM/TERMINFO/TERMINFO_DIRS, or injected bytes), applies environment evidence (COLORTERM), and returns a frozenDetectionwith staticCapabilities, theprobequery batch, and opaquekeysbytes.tasks/gen-fixtures.ts+test/fixtures.ts: generated terminfo fixtures (xterm-256color + synthetic entries) from terminfo.dev data.test/terminfo.test.ts: parser, baseline/evidence model, anddetectTerminal()behavior.Purely additive — no consumers yet, zero behavior change to rendering or input. Key-table and probe-response wiring land in #132.
Conforms to terminfo-spec §4–§7 (PR #130).