Repository navigation
feat: hex color strings for directive color fields - #146
Open
natemoo-re wants to merge 2 commits into
Open
natemoo-re wants to merge 2 commits into
natemoo-re wants to merge 2 commits into
Conversation
Color fields (open bg, border color/bg, border side color/bg, text
color/bg) accept a hex color string in addition to the packed ARGB
number. Hex grammar: '#' + exactly 3/4/6/8 hex digits, case-insensitive;
3/4-digit forms double each digit; missing alpha defaults to 255.
Conversion happens at the transfer-encoding boundary — hex strings never
appear on the wire; packed values are bit-identical to the equivalent
rgba() result. Invalid hex is invalid directive input: validate()
reports it and the packer MUST throw a TypeError before producing bytes.
Static types stay number | string; directive constructors check string
literals against the grammar at compile time (the TS equivalent of
#${string{3,4,6,8}}), reserving room for full CSS Color 4 syntax later.
Color fields (open bg, border color/bg, border side color/bg, text color/bg) accept '#RGB', '#RGBA', '#RRGGBB', and '#RRGGBBAA' alongside packed ARGB numbers. colorValue() expands strings at the transfer- encoding boundary (RRGGBBAA digit order -> AARRGGBB word layout, 3/4- digit forms double each digit, missing alpha = 255); the wire format and the C renderer are untouched. Directive constructors type-check string literals against the grammar via per-character recursion — a flat template union is unrepresentable (TS2590) at 6/8 digits — while computed strings pass through and are checked normatively by validate() and the packer. Invalid hex throws TypeError before any bytes are produced.
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 CSS-style hex color strings as an alternative to `rgba()` packed integers on every color field.
`open({ bg })`, `border.color`, `border.bg`, per-side `color`/`bg`, and `text({ color, bg })` now accept `#RGB`, `#RGBA`, `#RRGGBB`, or `#RRGGBBAA` strings (case-insensitive, `#` required). The wire format, snapshot encoding, and renderer are unchanged — strings are resolved to their packed ARGB value at the transfer-encoding boundary.
Invalid hex is caught at three layers: a compile-time type error for string literals, a `false` return from `validate()`, and a `TypeError` thrown by `pack()` before any bytes are written.
#### Migration
Color fields previously typed `number` are now typed `number | string`. Existing `rgba()` calls and numeric literals are unaffected. If you have wrapper types or overloads that constrain color fields to `number`, widen them to accept `string`:
```diff
-function themed(bg: number): OpenElement {
+function themed(bg: number | string): OpenElement {
return open("root", { bg });
}
```Review this changeset manually If this draft is correct, react with 🚀 and Cooper will commit it to this branch. |
| @@ -0,0 +1,13 @@ | |||
| --- | |||
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 CSS-style hex color strings as an alternative to `rgba()` packed integers on every color field.
`open({ bg })`, `border.color`, `border.bg`, per-side `color`/`bg`, and `text({ color, bg })` now accept `#RGB`, `#RGBA`, `#RRGGBB`, or `#RRGGBBAA` strings (case-insensitive, `#` required). The wire format, snapshot encoding, and renderer are unchanged — strings are resolved to their packed ARGB value at the transfer-encoding boundary.
Invalid hex is caught at three layers: a compile-time type error for string literals, a `false` return from `validate()`, and a `TypeError` thrown by `pack()` before any bytes are written.
#### Migration
Color fields previously typed `number` are now typed `number | string`. Existing `rgba()` calls and numeric literals are unaffected. If you have wrapper types or overloads that constrain color fields to `number`, widen them to accept `string`:
```diff
-function themed(bg: number): OpenElement {
+function themed(bg: number | string): OpenElement {
return open("root", { bg });
}
```|
Size Increased — +2.1 KB 124.8 KB unpacked |
commit: |
natemoo-re
marked this pull request as ready for review
October 12, 2026 01:07
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.
Stacked on #139.
Implements support for CSS-styled hex color strings alongside
rgba(). There's no C or wire format change, hex values are expanded to theirrgba()equivalent atpack()time.Supported hex grammar is
#RGBdexpands asd×17(#f80→#ff8800)#RGBA#f80a→#ff8800aa)#RRGGBB#RRGGBBAA