@@ -762,12 +762,14 @@ wherever the directive model expects a color.
762762` rgba() ` , or a CSS color ` string ` . Every directive field described as a color —
763763` open({ bg }) ` , ` border.color ` , ` border.bg ` , the ` color ` and ` bg ` fields of
764764structured border sides, and ` text({ color, bg }) ` — accepts both forms. Each
765- color string is resolved to a packed ARGB value at the transfer-encoding
766- boundary (§9.2), so color strings MUST NOT appear in the transfer encoding.
767- Every color string except a system color resolves to packed sRGB ARGB, and its
768- wire, snapshot, and cell encoding is bit-identical to the equivalent ` rgba() `
769- value. System colors resolve to terminal-themed colors instead (see ** System
770- colors** below).
765+ color string is parsed at the transfer-encoding boundary (§9.2), so color
766+ strings MUST NOT appear in the transfer encoding. Every color string except a
767+ system color or ` currentcolor ` resolves to packed sRGB ARGB, and its wire,
768+ snapshot, and cell encoding is bit-identical to the equivalent ` rgba() ` value.
769+ System colors and ` currentcolor ` depend on where the directive sits in the
770+ rendered frame and on the terminal's theme, so the renderer resolves them when
771+ the frame renders, not when the directive is packed (see ** Render-time
772+ resolution** below).
771773
772774** Color string grammar.** A color string is one of the following CSS Color
773775Module Level 4 forms. Function names and keywords are case-insensitive. Leading
@@ -830,14 +832,14 @@ field, or a background-default keyword in a foreground field, including a border
830832side's ` color ` — it resolves to the terminal's probed color for the attribute it
831833names, not to that field's default. The renderer reads this from the OSC 10/11
832834theme probe, surfaced as ` RuntimeCapabilities.theme.foreground ` / ` .background `
833- (terminfo-spec §6.4) and passed into ` pack() ` as the theme snapshot
834- ` term.render() ` holds at render time (§12.5). The result is an ordinary opaque
835- sRGB color (alpha 255): it packs exactly like the equivalent ` rgba() ` value,
836- renders as truecolor, and transitions interpolate it like any other RGB color —
837- unlike the terminal-themed colors described below. When the theme has not yet
838- reported that color, the keyword falls back to its field's own terminal default
839- instead (the same-field behavior above). A theme report that arrives after a
840- frame renders takes effect starting with the next render.
835+ (terminfo-spec §6.4), using the theme in effect when the frame renders. The
836+ result is an ordinary opaque sRGB color (alpha 255): it renders exactly like the
837+ equivalent ` rgba() ` value, as truecolor, and transitions interpolate it like any
838+ other RGB color — unlike the terminal-themed colors described below. When the
839+ theme has not yet reported that color, the keyword falls back to its field's own
840+ terminal default instead ( the same-field behavior above). A theme report that
841+ ` update() ` folds in after a frame renders takes effect starting with the next
842+ render.
841843
842844For example, once the terminal has reported its default foreground color,
843845` text({ bg: "CanvasText" }) ` paints that color as an opaque truecolor
@@ -888,8 +890,7 @@ overrides it for that element and, by the same inheritance rule, every
888890descendant that does not itself override it. ` text() ` resolves its own ` color `
889891field (and, when absent, inherits) the same way; a ` text() ` has no descendants,
890892so its resolved color only affects itself. With no ` color ` anywhere in the
891- enclosing chain, the inherited color is the terminal default foreground — the
892- same color a directive gets today when ` color ` is omitted.
893+ enclosing chain, the inherited color is the terminal default foreground.
893894
894895` currentcolor ` used in any field other than ` color ` — ` open({ bg }) ` ,
895896` text({ bg }) ` , ` border.color ` , ` border.bg ` , or a structured border side's
@@ -911,11 +912,21 @@ structured border side without its own `color` falls back to the shared
911912` border.color ` as before, and so, transitively, to the inherited color when
912913` border.color ` is omitted.
913914
914- Foreground inheritance is resolved by ` pack() ` with a stack: pushed on each
915- element open (the newly resolved color), popped on the matching close. It is
916- scoped to the single pass over one frame's directive array — a sibling that
917- follows a closed element does not see that element's color, and no inheritance
918- state carries across frames (§6, §10.4).
915+ ** Render-time resolution.** Foreground inheritance, ` currentcolor ` , and the
916+ field resolution of system colors follow the element tree of the frame being
917+ rendered. An element's inherited color comes from its ancestors in that frame —
918+ a sibling that follows a closed element does not see that element's color — and
919+ a cross-field default keyword resolves against the theme in effect for that
920+ render. No inheritance state carries across frames (§6, §10.4).
921+
922+ Directives that reach the renderer already packed resolve by the same rule. A
923+ snapshot's directives inherit from the ancestors at the position where the
924+ snapshot appears in the frame, and resolve against the theme of the render that
925+ contains it, exactly as if its source ops were spliced there (§9.1). The
926+ inherited color and theme in effect when the snapshot was created have no
927+ effect. For example, a snapshot of ` text("hi") ` created at the root renders in
928+ the terminal default foreground at the root, and in red when it appears inside
929+ ` open("a", { color: "red" }) ` .
919930
920931** Invalid color strings.** A string that does not match the color string grammar
921932is invalid directive input (§9.1). ` validate() ` reports it as an invalid field
@@ -1148,16 +1159,24 @@ opcode values, mask definitions, and field layouts are implementation details
11481159and are not locked down by this specification.
11491160
11501161** Color words.** Text colors and border side colors travel as one 32-bit
1151- attribute word each, in the same encoding the renderer stores in its cells. When
1152- bit 31 is clear, the low 24 bits are an sRGB color (` 0x00RRGGBB ` ). When bit 31
1153- is set, the color is terminal-themed: ` 0x80000000 ` is the terminal default, and
1154- ` 0x80000100 | n ` is ANSI palette entry ` n ` (0–15). Text foreground carries bit
1155- 31 in the text attribute byte rather than in the color word. A background word
1156- of ` 0x40000000 ` means "keep the existing cell background" and is used for an
1157- omitted ` bg ` ; it never appears in a cell. Element backgrounds keep their full
1158- packed ARGB word, because alpha 0 suppresses the fill; a terminal-themed element
1159- background sets an additional property-mask bit that marks its background word
1160- as a color word.
1162+ attribute word each. When bit 31 is clear, the low 24 bits are an sRGB color
1163+ (` 0x00RRGGBB ` ). When bit 31 is set, the word is symbolic and the renderer
1164+ resolves it while rendering the frame (§8.5): ` 0x80000100 | n ` is ANSI palette
1165+ entry ` n ` (0–15), ` 0x80000200 ` and ` 0x80000400 ` are the foreground- and
1166+ background-default keywords, and ` 0x80000800 ` is ` currentcolor ` . Text foreground
1167+ carries bit 31 in the text attribute byte rather than in the color word; an
1168+ omitted text ` color ` packs as ` currentcolor ` . A background word of ` 0x40000000 `
1169+ means "keep the existing cell background" and is used for an omitted ` bg ` .
1170+ Element backgrounds and an element's own ` color ` keep their full packed ARGB
1171+ word, because alpha 0 suppresses the fill; a symbolic one sets an additional
1172+ property-mask bit that marks the word as a color word.
1173+
1174+ Packing depends on neither the enclosing directives nor the theme, so a
1175+ directive packs to the same words wherever it appears; that is what lets a
1176+ snapshot resolve at its splice position (§8.5). Cells hold only resolved colors:
1177+ sRGB, ` 0x80000000 ` for the terminal default of the cell's foreground or
1178+ background, or ` 0x80000100 | n ` for a palette entry. The keyword,
1179+ ` currentcolor ` , and keep-background words never appear in a cell.
11611180
11621181### 12.2 Directive property groups
11631182
@@ -1410,16 +1429,15 @@ structural errors (unbalanced open/close pairs, invalid field types — includin
14101429color fields, which must be a packed ARGB number or a §8.5 CSS color string).
14111430Exported and used in tests.
14121431
1413- ** ` pack(ops, mem, offset, limit?, theme?) ` ** — An internal function that
1414- serializes a directive array into the transfer encoding described in Section
1415- 12.1. Currently exported but not public API; its exposure is incidental to the
1416- module structure. The optional trailing ` theme ` carries the probed default
1417- foreground/background colors (` RuntimeCapabilities.theme ` , terminfo-spec §6.4),
1418- used to resolve a cross-field default keyword (§8.5) to the terminal's actual
1419- default color. ` term.render() ` passes its current capability snapshot's ` theme ` ;
1420- a caller that omits it gets the field-default fallback for every cross-field
1421- keyword. ` pack() ` also resolves ` color ` inheritance and ` currentcolor ` (§8.5)
1422- with a stack scoped to the single call.
1432+ ** ` pack(ops, mem, offset, limit?) ` ** — An internal function that serializes a
1433+ directive array into the transfer encoding described in Section 12.1. Currently
1434+ exported but not public API; its exposure is incidental to the module structure.
1435+ ` pack() ` parses color strings but resolves neither ` color ` inheritance,
1436+ ` currentcolor ` , nor system color fields (§8.5); those stay symbolic in the
1437+ transfer encoding. The renderer holds the probed theme colors
1438+ (` RuntimeCapabilities.theme ` , terminfo-spec §6.4) in native state: ` update() `
1439+ passes them across when a theme report changes them, and ` render() ` does not
1440+ transfer them.
14231441
14241442---
14251443
0 commit comments