Repository navigation
feat: CSS system colors map to the ANSI 16-color palette - #157
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 should start with an approved active present-tense verb. Changeset package scope does not match the affected packages confidently. Changeset does not name the affected public API confidently. Changeset contains unsupported consumer-facing claims. View the proposed changeset---
'@bomb.sh/tty': minor
---
Adds support for CSS Color 4 system color keywords (`Canvas`, `CanvasText`, `LinkText`, `Highlight`, `GrayText`, `Mark`, `AccentColor`, and the full set) in every color field.
Keywords are accepted case-insensitively. Background-default keywords (`Canvas`, `ButtonFace`, `Field`) and foreground-default keywords (`CanvasText`, `ButtonText`, `FieldText`) used in their own field emit SGR `39`/`49`, leaving the terminal's theme in control. Palette keywords (`LinkText` → blue, `GrayText` → bright black, etc.) emit the corresponding ANSI 16-color SGR code.
#### Cross-field default keywords
A default keyword used in the opposite field resolves to the terminal's probed color (from the OSC 10/11 theme report surfaced as `RuntimeCapabilities.theme`) and renders as an ordinary opaque truecolor value. Until the terminal reports that color, it falls back to the field's own terminal default.
```diff
- open("box", { bg: "Canvas" }); // was a type error ("reserved system color")
+ open("box", { bg: "Canvas" }); // terminal default background, theme-controlled
- text("hi", { color: "LinkText" }); // was a type error
+ text("hi", { color: "LinkText" }); // ANSI palette 4 (blue)
+ text("hi", { bg: "CanvasText" });
+ // once OSC 11 reports fg: renders as truecolor; until then: terminal default bg
```
Transitions between a terminal-themed color and any other color change discretely at 50% progress rather than interpolating. A cross-field default keyword that has resolved to a probed sRGB value interpolates normally.Review this changeset manually If this draft is correct, react with 🚀 and Cooper will commit it to this branch. |
| @@ -0,0 +1,19 @@ | |||
| --- | |||
There was a problem hiding this comment.
Changeset needs revision.
Changeset should start with an approved active present-tense verb. Changeset package scope does not match the affected packages confidently. Changeset does not name the affected public API confidently. Changeset contains unsupported consumer-facing claims.
View the proposed replacement
---
'@bomb.sh/tty': minor
---
Adds support for CSS Color 4 system color keywords (`Canvas`, `CanvasText`, `LinkText`, `Highlight`, `GrayText`, `Mark`, `AccentColor`, and the full set) in every color field.
Keywords are accepted case-insensitively. Background-default keywords (`Canvas`, `ButtonFace`, `Field`) and foreground-default keywords (`CanvasText`, `ButtonText`, `FieldText`) used in their own field emit SGR `39`/`49`, leaving the terminal's theme in control. Palette keywords (`LinkText` → blue, `GrayText` → bright black, etc.) emit the corresponding ANSI 16-color SGR code.
#### Cross-field default keywords
A default keyword used in the opposite field resolves to the terminal's probed color (from the OSC 10/11 theme report surfaced as `RuntimeCapabilities.theme`) and renders as an ordinary opaque truecolor value. Until the terminal reports that color, it falls back to the field's own terminal default.
```diff
- open("box", { bg: "Canvas" }); // was a type error ("reserved system color")
+ open("box", { bg: "Canvas" }); // terminal default background, theme-controlled
- text("hi", { color: "LinkText" }); // was a type error
+ text("hi", { color: "LinkText" }); // ANSI palette 4 (blue)
+ text("hi", { bg: "CanvasText" });
+ // once OSC 11 reports fg: renders as truecolor; until then: terminal default bg
```
Transitions between a terminal-themed color and any other color change discretely at 50% progress rather than interpolating. A cross-field default keyword that has resolved to a probed sRGB value interpolates normally.|
Size Increased — +5.8 KB 139.4 KB unpacked |
commit: |
d9caccc to
f010a29
Compare
f45c56e to
f28eb00
Compare
…§8.5) System color keywords stop being reserved and resolve to terminal-themed colors: the terminal default foreground/background, or palette entries 0-15, per a fixed keyword table. currentcolor stays reserved. The six default keywords (Canvas, CanvasText, ButtonFace, ButtonText, Field, FieldText) all mean "the terminal default for this attribute". CanvasText in a bg field is the default background, and Canvas in a fg field the default foreground. SGR has no way to paint the default foreground as a background, and approximating it with a palette entry is wrong on either light or dark themes, so the field decides. Rejecting the cross-field keywords was the alternative; it would need a role-aware resolver, validator, and literal checker for little gain. Encoding (§12.1, descriptive). Cells and the text/border color words share one encoding: bit 31 clear is 0x00RRGGBB, bit 31 set is terminal-themed, with 0x80000000 the default and 0x80000100|n palette n. bit 31 is already ATTR_DEFAULT and the fg high byte has no free bits, so reusing the low bits under it costs no cell width and keeps diffing an exact compare (each color has one canonical word). It forces the wire-only "keep existing bg" sentinel off 0x80000000 (now 0x40000000), since an explicit Canvas bg must overwrite while an omitted bg keeps. Element bg keeps its full ARGB word, since alpha 0 suppresses the fill and every bit is in use, so a terminal-themed element bg sets a new property-mask bit instead. sRGB colors stay bit-identical on the wire. Widening the cell with a separate flags word was the other option; it grows every cell by 4 bytes for information that fits in unused bits. Transitions can't interpolate a color the renderer has no RGB for, so a terminal-themed endpoint switches discretely at eased progress 0.5, matching CSS discrete animation.
resolveColor() checks a lowercase keyword table before hueful and
returns a TerminalColor ({ ansi: index | "default" }) for system colors,
so validate() accepts them through the existing css-color format and the
CheckedColor literal check gains them via the same table.
The packer turns a TerminalColor into a color word: 0x80000000 for the
default, 0x80000100|n for palette n. Text fg keeps bit 31 in the attrs
byte as before, so an omitted color and a default keyword pack
identically. The omitted-bg sentinel for text and border words moves to
BG_KEEP (0x40000000) so an explicit Canvas bg can be 0x80000000 and
overwrite. Element bg keeps its ARGB word; PROP_BG_TERMINAL (0x100) marks
the word as a color word instead.
Element bg reaches render_rect through Clay_Color floats, so the C side
carries a terminal color as r = -1 with g = palette index (or -1 for the
default) and a = 255, which survives the float round trip and keeps
Clay's a > 0 rectangle check. color() maps it back to the cell word.
lerp_color() switches discretely at 0.5 when either endpoint carries
that marker, instead of interpolating a meaningless channel.
emit_attr() emits SGR 30-37/90-97 and 40-47/100-107 for palette words
and leaves defaults to the leading SGR reset, as before. Cells compare
with the same integer equality; each color has one canonical word.
A default keyword named in the other attribute's field (CanvasText in a bg field, Canvas in a fg field, including border fg) now resolves to the OSC 10/11-probed theme color for the attribute it names, as an ordinary opaque sRGB color that packs and interpolates like rgba(). Falls back to the field's own terminal default when the theme hasn't reported that color. pack() gains an optional trailing theme parameter; term.render() passes it.
pack() gains an optional trailing theme parameter (RuntimeCapabilities.theme shape); term.render() passes currentCaps.theme every frame. color.ts's systemColors now tags each default keyword with which attribute it names (fg-default/bg-default) instead of a single undifferentiated "default", and resolveForField() picks the terminal default for a same-field keyword or the probed theme color for a cross-field one, falling back to the field's own default when that color hasn't been probed yet. Covers pack-level byte identity against rgba(), the no-theme fallback, and render-through-Term cases (text bg, element bg, border side fg) that pick up a theme color after term.update() folds in an OSC 10/11 CapabilityEvent.
f28eb00 to
585db6c
Compare
Canvas,CanvasText,LinkText, andHighlight, case-insensitive.Canvas/CanvasTextand friends mean "terminal default". Used in the other slot (bg: "CanvasText"), they paint the real default color the terminal reported in its theme probe. With no probe answer, they fall back to that slot's default.