Skip to content

feat: terminfo capability core (parser, detectTerminal) - #131

Draft
natemoo-re wants to merge 5 commits into
spec/terminfo-layerfrom
feat/terminfo-core
Draft

natemoo-re wants to merge 5 commits into
spec/terminfo-layerfrom
feat/terminfo-core

Conversation

@natemoo-re

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

Copy link
Copy Markdown
Member

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 (legacy 011a and extended 021e formats), the TermInfo struct (colors, flags, confirmed theme values), and the terminfo_init/parse/grant/confirm exports.
  • terminfo.ts: public detectTerminal() API — resolves a terminfo entry (filesystem via TERM/TERMINFO/TERMINFO_DIRS, or injected bytes), applies environment evidence (COLORTERM), and returns a frozen Detection with static Capabilities, the probe query batch, and opaque keys bytes.
  • 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, and detectTerminal() 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).

@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

This 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.

Add this changeset manually

If this draft is correct, react with 🚀 and Cooper will commit it to this branch.

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Size Increased — +8.8 KB

111.6 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@131

commit: c041c67

@natemoo-re natemoo-re changed the title feat/terminfo core feat: terminfo capability core (parser, detectTerminal) Sep 19, 2026
Comment thread src/terminfo.c Outdated
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.
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.

2 participants