@@ -814,22 +814,42 @@ color; the terminal applies its own theme when it draws the cell.
814814| ` HighlightText ` , ` SelectedItemText ` | palette 15 (bright white) |
815815| ` MarkText ` , ` AccentColorText ` | palette 0 (black) |
816816
817- The six default keywords name the terminal default color of the attribute the
818- field sets, whichever keyword is used. In a foreground field (` text({ color }) ` ,
819- ` border.color ` , a border side's ` color ` ) each of them resolves to the terminal
820- default foreground; in a background field (` open({ bg }) ` , ` text({ bg }) ` ,
821- ` border.bg ` , a border side's ` bg ` ) each resolves to the terminal default
822- background. ` text({ bg: "CanvasText" }) ` therefore renders the default
823- background, not the default foreground color painted as a background: a terminal
824- offers no way to paint its default foreground color as a cell background, and
825- the renderer does not guess one.
826-
827- A terminal-themed color is opaque. A palette color in a foreground field is
828- emitted as SGR ` 30 ` –` 37 ` for palette 0–7 and ` 90 ` –` 97 ` for palette 8–15; in a
829- background field, as SGR ` 40 ` –` 47 ` and ` 100 ` –` 107 ` . A terminal default color is
830- emitted as SGR ` 39 ` (foreground) or ` 49 ` (background), or by omitting the
831- foreground or background SGR after an SGR reset, which leaves the same default
832- in effect.
817+ Each default keyword names the terminal default color of one specific
818+ attribute: ` Canvas ` , ` ButtonFace ` , and ` Field ` name the default background;
819+ ` CanvasText ` , ` ButtonText ` , and ` FieldText ` name the default foreground.
820+ ** Used in its own field** — a background-default keyword in a background
821+ field (` open({ bg }) ` , ` text({ bg }) ` , ` border.bg ` , a border side's ` bg ` ), or
822+ a foreground-default keyword in a foreground field (` text({ color }) ` ,
823+ ` border.color ` , a border side's ` color ` ) — it resolves to that field's
824+ terminal default, unchanged from the table above.
825+
826+ ** Used in the other field** — a foreground-default keyword in a background
827+ field, or a background-default keyword in a foreground field, including a
828+ border side's ` color ` — it resolves to the terminal's probed color for the
829+ attribute it names, not to that field's default. The renderer reads this from
830+ the OSC 10/11 theme probe, surfaced as ` RuntimeCapabilities.theme.foreground `
831+ / ` .background ` (terminfo-spec §6.4) and passed into ` pack() ` as the theme
832+ snapshot ` term.render() ` holds at render time (§12.5). The result is an
833+ ordinary opaque sRGB color (alpha 255): it packs exactly like the equivalent
834+ ` rgba() ` value, renders as truecolor, and transitions interpolate it like any
835+ other RGB color — unlike the terminal-themed colors described below. When the
836+ theme has not yet reported that color, the keyword falls back to its field's
837+ own terminal default instead (the same-field behavior above). A theme report
838+ that arrives after a frame renders takes effect starting with the next
839+ render.
840+
841+ For example, once the terminal has reported its default foreground color,
842+ ` text({ bg: "CanvasText" }) ` paints that color as an opaque truecolor
843+ background. Until then it falls back to the default background: a terminal
844+ offers no way to paint its default foreground color as a cell background
845+ without knowing its RGB value, and the renderer never guesses one.
846+
847+ A terminal-themed color (a same-field default, or a palette entry) is opaque.
848+ A palette color in a foreground field is emitted as SGR ` 30 ` –` 37 ` for palette
849+ 0–7 and ` 90 ` –` 97 ` for palette 8–15; in a background field, as SGR ` 40 ` –` 47 `
850+ and ` 100 ` –` 107 ` . A terminal default color is emitted as SGR ` 39 ` (foreground)
851+ or ` 49 ` (background), or by omitting the foreground or background SGR after
852+ an SGR reset, which leaves the same default in effect.
833853
834854A terminal default background is a color, not the absence of one. An explicit
835855` Canvas ` background (or ` ButtonFace ` , ` Field ` , or any default keyword in a
@@ -847,7 +867,9 @@ A transition (see the Transitions Specification) cannot interpolate between a
847867terminal-themed color and any other color. When either endpoint of an
848868interpolated color is terminal-themed, the color changes discretely: it holds
849869the initial value while eased progress is below 0.5 and takes the target value
850- from 0.5 on.
870+ from 0.5 on. A cross-field default keyword resolved to a probed theme color is
871+ not terminal-themed — it is an ordinary opaque sRGB color — so it interpolates
872+ normally; only the unprobed fallback and same-field defaults are discrete.
851873
852874** Resolution.** A color string resolves to sRGB, then to a packed ARGB value:
853875each of R, G, B is clamped to [ 0, 255] and rounded to the nearest integer; alpha
@@ -1344,9 +1366,15 @@ structural errors (unbalanced open/close pairs, invalid field types — includin
13441366color fields, which must be a packed ARGB number or a §8.5 CSS color string).
13451367Exported and used in tests.
13461368
1347- ** ` pack(ops, mem, offset) ` ** — An internal function that serializes a directive
1348- array into the transfer encoding described in Section 12.1. Currently exported
1349- but not public API; its exposure is incidental to the module structure.
1369+ ** ` pack(ops, mem, offset, limit?, theme?) ` ** — An internal function that
1370+ serializes a directive array into the transfer encoding described in Section
1371+ 12.1. Currently exported but not public API; its exposure is incidental to the
1372+ module structure. The optional trailing ` theme ` carries the probed default
1373+ foreground/background colors (` RuntimeCapabilities.theme ` , terminfo-spec
1374+ §6.4), used to resolve a cross-field default keyword (§8.5) to the terminal's
1375+ actual default color. ` term.render() ` passes its current capability
1376+ snapshot's ` theme ` ; a caller that omits it gets the field-default fallback for
1377+ every cross-field keyword.
13501378
13511379---
13521380
0 commit comments