Repository navigation
feat: currentcolor and inherited open() color - #158
Draft
natemoo-re wants to merge 2 commits into
Draft
natemoo-re wants to merge 2 commits into
natemoo-re wants to merge 2 commits into
Conversation
Replaces the "currentcolor is reserved" wording. open() gains a color field, inherited by descendants unless overridden; currentcolor means "inherit" in a color field and "this directive's own resolved color, field-resolved like any other color" everywhere else. border.color becomes optional, defaulting to currentcolor. Inheritance is a pack()-time stack scoped to one frame's directive array.
open() gains a color field: the element's own foreground, inherited by descendants via a pack()-time stack pushed on open and popped on close. currentcolor means "inherit" in a color field and "this directive's own resolved color" everywhere else, going through the same field resolution (resolveForField) as any other color. border.color is now optional and defaults to currentcolor. resolveColor() returns a CURRENT_COLOR sentinel for the keyword; ops.ts substitutes the inherited/own color before field resolution via resolveOwn()/colorValue(), both newly threading a `current` parameter through colorWord/sideFg/sideBg. No wire-format change: open()'s own color has no direct rendering, only TS-side inheritance.
Contributor
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. View the proposed changeset---
'@bomb.sh/tty': minor
---
Adds `color` to `open()`: the element's own foreground color, inherited by every descendant that does not set its own.
`currentcolor` is now a valid color string at every color field. In `open({ color })` and `text({ color })` it means "inherit" (same as omitting the field); in any other field — `bg`, `border.color`, `border.bg`, or a structured border side's `color`/`bg` — it resolves to the directive's own resolved foreground, then follows normal field resolution (terminal-themed for same-field defaults, theme-probed for cross-field defaults, pass-through for sRGB).
`border.color` is now optional and defaults to `currentcolor`, matching CSS; a border with no `color` set anywhere inherits the element's foreground as before.
Foreground inheritance is resolved by `pack()` with a stack scoped to a single call: pushed on each `open()`, popped on the matching `close()`. No state carries across frames.
#### Migration
`border.color` was previously required. It is now optional.
```diff
- open("box", { border: { color: "red", top: 1 } })
+ open("box", { border: { top: 1 } }) // inherits element color via currentcolor
```
Existing code that sets `border.color` explicitly is unaffected.
The string `"currentcolor"` was previously rejected as an invalid color string. Code that tested for that rejection will need to be updated.
```diff
- expect(validate([open("a", { bg: "currentcolor" }), close()])).toBe(false)
+ expect(validate([open("a", { bg: "currentcolor" }), close()])).toBe(true)
```Review this changeset manually If this draft is correct, react with 🚀 and Cooper will commit it to this branch. |
| @@ -0,0 +1,16 @@ | |||
| --- | |||
Contributor
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.
View the proposed replacement
---
'@bomb.sh/tty': minor
---
Adds `color` to `open()`: the element's own foreground color, inherited by every descendant that does not set its own.
`currentcolor` is now a valid color string at every color field. In `open({ color })` and `text({ color })` it means "inherit" (same as omitting the field); in any other field — `bg`, `border.color`, `border.bg`, or a structured border side's `color`/`bg` — it resolves to the directive's own resolved foreground, then follows normal field resolution (terminal-themed for same-field defaults, theme-probed for cross-field defaults, pass-through for sRGB).
`border.color` is now optional and defaults to `currentcolor`, matching CSS; a border with no `color` set anywhere inherits the element's foreground as before.
Foreground inheritance is resolved by `pack()` with a stack scoped to a single call: pushed on each `open()`, popped on the matching `close()`. No state carries across frames.
#### Migration
`border.color` was previously required. It is now optional.
```diff
- open("box", { border: { color: "red", top: 1 } })
+ open("box", { border: { top: 1 } }) // inherits element color via currentcolor
```
Existing code that sets `border.color` explicitly is unaffected.
The string `"currentcolor"` was previously rejected as an invalid color string. Code that tested for that rejection will need to be updated.
```diff
- expect(validate([open("a", { bg: "currentcolor" }), close()])).toBe(false)
+ expect(validate([open("a", { bg: "currentcolor" }), close()])).toBe(true)
```|
Size Increased — +3.2 KB 141.4 KB unpacked |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
open()gets acolorfield. Nestedopen()s andtext()s inherit it unless they set their own, like CSScolor.currentcolorworks in every color field and means "this element's color". Ascoloritself, it means inherit.border.coloris now optional and defaults tocurrentcolor, so borders match the text color by default.currentcolornever throws. If the color it points at is the terminal default and it's used as a background, it paints the theme foreground the terminal reported, or falls back to the default background.