Skip to content

feat: color-encoding tiers derived from capability evidence - #148

Merged
natemoo-re merged 9 commits into
mainfrom
feat/color-encoding-modes
Dec 3, 2026
Merged

natemoo-re merged 9 commits into
mainfrom
feat/color-encoding-modes

Conversation

@natemoo-re

@natemoo-re natemoo-re commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Closes #60.

  • The renderer picks a color tier from what it knows about the terminal instead of always sending 24-bit truecolor: truecolor evidence → 38;2;R;G;B, more than 16 colors → 38;5;N, 16 or fewer → 3x/9x
  • RGB colors stay fixed colors where the terminal allows it: in 256-color output they only use the cube and gray ramp, never the theme-controlled 0–15, so rgba(255,0,0) → \x1b[38;5;196m. 16-color output has no fixed colors, so it picks the nearest palette entry (\x1b[31m). Want the theme's red? Use -ansi-red. This departs from 💡 Color-encoding modes (16-color / 256-color) derived from terminfo #60's 38;5;1m, which was written before the -ansi-* keywords existed
  • No colorMode override. Capability evidence is the only input, so it can't contradict probe results. To get truecolor, pass detectTerminal() or fold probe replies through term.update()
  • Capability evidence lives in WASM (answers Charles' question on feat: term.update() folds CapabilityEvents into runtime capabilities #133). It's pushed at creation and after updates, and kept across resizes
  • The tier each frame was drawn in is tracked on the frame itself, like the pointer shape. If it differs from the last frame's, the whole screen is redrawn
  • Works with feat: CSS system colors map to the ANSI 16-color palette #157/feat: currentcolor and inherited open() color #158: -ansi-* palette colors are already 4-bit and come out the same in every tier. A Canvas/CanvasText resolved from the probed theme is plain RGB and gets encoded for the current tier
  • ⚠️ Default change: with no evidence, output is now 256-color instead of truecolor. That matches terminfo-spec §7.1, and the changeset includes a migration snippet. Truecolor output is byte-identical to before
  • Spec: new specs/color-encoding-spec.md, which only covers what users see: how the tier is picked, the escape codes, how colors map down, and the redraw on tier change. renderer-spec §8.5 no longer says theme colors render "as truecolor"
  • Tests: test/color-encoding-modes.test.ts covers every tier, the boundaries, a full 256 round-trip, defaults, palette pass-through, and theme-color tiering. Suites that pin truecolor bytes now pass a shared truecolor fixture

@bombshell-cooper

This comment was marked as outdated.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Size Increased — +1.4 KB

143.7 KB unpacked

@pkg-pr-new

pkg-pr-new Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 9bd1f67

natemoo-re and others added 2 commits December 3, 2026 08:50
The renderer resolves an emission tier (truecolor / 256 / 16) from its
capability snapshot instead of hardcoding 24-bit truecolor, per
specs/color-encoding-spec.md. Capability state is authoritative in the
WASM instance; the host pushes it at creation and after capability
folds, and a tier change forces a complete redraw. Standard palette
colors keep their classic indices when downmapped.

Terminal-themed colors from the system-color work bypass downmapping:
-ansi-* palette colors are already 4-bit and emit unchanged in every
tier, while a cross-field Canvas/CanvasText resolved from the probed
theme is ordinary sRGB and is encoded for the active tier.

Closes #60

@cowboyd cowboyd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a few comments on keeping the specs from getting too big, and also about where to keep current and previous state.

Comment thread specs/color-encoding-spec.md Resolved
Comment thread specs/renderer-spec.md Resolved
Comment thread src/clayterm.c Resolved
Drop the architecture diagram, WASM state-ownership notes, test plan,
rejected-alternative discussion, and deferred-work list; keep tier
resolution, emission formats, downmapping, and tier-change output.
Sections renumber accordingly (resolution §5, formats §6, downmapping
§7, tier changes §8).

renderer-spec §7.8 no longer references follow-up PR sequencing.
The emitted tier is per-frame output state, like pointer_shape, so it
lives on Frame instead of the Clayterm instance. write_current_frame
resolves current->color_tier and compares it against previous's to
decide on a full redraw; the frame swap carries it forward, so the
separate last_tier sentinel goes away. Also repoints code comments at
the renumbered spec sections.
@bombshell-dev bombshell-dev deleted a comment from bombshell-cooper Bot Dec 3, 2026

@cowboyd cowboyd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

doooooope. 🏄🏻

Since #157/#158, a cell's color is known only after render-time field
resolution (inheritance, currentcolor, system colors). The tier now
applies explicitly to that resolved color; terminal default and palette
colors defer to renderer-spec §8.5 instead of restating it, which also
drops a "no color SGR" rule that contradicted §8.5's allowance of
SGR 39/49. renderer-spec's "unchanged cell MUST NOT be re-emitted" gains
the CI-5 tier-change exception, and §7.1 notes that `red` downmaps while
`-ansi-red` is palette 1 in every tier.
An inherited open() color and a currentcolor background that resolve to
sRGB downmap like any other sRGB color. The default-color test now
asserts tier-independent bytes rather than the absence of any color
SGR, matching CI-6.
An sRGB color is a fixed color, but mapping #ff0000 to palette index 1
made its appearance depend on the user's theme: a terminal that sets
index 1 to pink rendered `red` pink in 256-color output and red in
truecolor. #60 asked for `\x1b[38;5;1m` before the `-ansi-*` keywords
existed; now that they do, they are the way to ask for the theme's
colors.

The 256 tier maps only onto the cube and grayscale ramp (16-255), so
standard red emits 196. CI-4 becomes "every cube and ramp color maps to
its own index". The 16 tier keeps nearest-nominal mapping, since it has
no fixed alternative; the spec says so directly.
Drop the exact-nominal rule from map_256 so sRGB never lands on the
theme-controlled indices 0-15. Standard red now emits 38;5;196, and the
256 round-trip sweep asserts that nominal colors stay at 16 or above
while every cube and ramp color maps to its own index.
@natemoo-re
natemoo-re merged commit 6cbbaf4 into main Dec 3, 2026
13 checks passed
@natemoo-re
natemoo-re deleted the feat/color-encoding-modes branch December 3, 2026 18:08
@bombshell-bot bombshell-bot Bot mentioned this pull request Dec 3, 2026
natemoo-re added a commit that referenced this pull request Dec 4, 2026
Main landed void update() (#166), element replay (#171), the retained
frame pair (#169), cell coverage (#168), color encoding tiers (#148,
#157, #158), synchronized output (#139), and pointer shape (#137).

- update() can no longer return cleanup bytes, so resize and
  kitty-graphics denial enqueue wire image ids in a new fixed-capacity
  pending-deletion queue (§5.7); the next completed render emits the
  data-freeing deletions first (§9.2.6 step 0). Overflow collapses to
  one delete-all with transmission resets.
- removeImage() returns void and uses the same queue, resolving Open
  Decision 4: render() is the Term's only output path.
- Replay equivalence replaces snapshot equivalence; a replay carries
  the directive, never a resolution.
- Placements tables follow the frame pair's roles; INV-I9 maps onto
  discarding the current frame.
- Layout-box cell quantities are measured on the covered-cell rect
  (renderer-spec §7.11).
- img bg takes the full color value space; ascii art colors encode at
  the frame's color tier; a color-tier change re-places without
  re-transmitting.
- Graphics bytes sit inside the BSU/ESU pair; a graphics-only frame is
  not a no-op. §16.9 is dropped.
- Probe query renumbered to 10; §4.5 moved to §4.4.
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.

💡 Color-encoding modes (16-color / 256-color) derived from terminfo

2 participants