You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(ghostty): import palette indexes written in hex, octal, binary or with a plus sign - #50608
Ghostty lets you number palette colors in hex, octal or binary (like 0x1 for color 1). When Orca imported a Ghostty config, it read all of those as color 0, so they all landed on black and the colors you actually picked were lost. Now Orca reads those numbers the same way Ghostty does.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$34
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$34
Prod
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$11
$\color{#cf222e}{\Huge{\mathbf{−}}}$2
$\color{#1a7f37}{\Huge{\mathbf{+}}}$9
What Changed
Before: the importer parsed palette indexes with Number.parseInt(idx, 10). 0x1, 0o3 and 0b10 all became 0 (black), and junk like 1wrong was read as 1, overwriting a valid red.
After:src/main/ghostty/mapper.ts matches the index against the same grammar Ghostty uses (std.fmt.parseInt(u8, s, 0) in src/terminal/color.zig): an optional +/-, decimal or 0x/0o/0b (any letter case), and _ only between digits. Underscores are stripped before the 0-15 slot lookup. Negative values other than -0 are skipped, matching u8 parsing. Anything else is skipped and no longer overwrites a valid entry.
Why
Before this change, imported Ghostty themes using non-decimal indexes came out wrong. Mirroring Ghostty's parser exactly, instead of adding a looser prefix check, keeps every index Ghostty accepts (including +5, -0, 1_5 and 0x0_e, which parseInt already handled) and rejects the ones Ghostty rejects.
N/A. This is a config-import data fix with no new UI. Before/after is shown by the regression tests plus a probe that checks each index against Ghostty's own Zig parseInt results (0x1, 0X2, 0o3, 0b101, 1_0, 0x0_f, -0, +0xF, 1wrong, _1, 1_, 0x_1, 0x100, 256, -1, 00x1, 1e1, ...):
Before (origin/main)
After (this PR)
Most radix, underscore and junk-suffix cases differ from Ghostty: hex/octal/binary indexes collapse onto black and 1wrong overwrites red
Every probed index maps to the same slot as Ghostty, or is skipped where Ghostty raises an error
Testing
src/main/ghostty/palette-index-import.test.ts (3 tests): radix prefixes map to the right ANSI slots; signed and underscore-separated indexes match Ghostty; malformed indexes (1wrong, -1, _1, 1_, 0x_1) don't override earlier entries. The radix and malformed tests fail on main.
Read Ghostty's parsePaletteEntry on upstream main to confirm the grammar (std.fmt.parseInt(u8, trim(key, " \t"), 0)).
Tested on macOS (vitest). The change is pure string parsing, so it behaves the same on every platform.
CI static gates on the touched files pass: anti-slop, native code-quality plugins, ast-grep and the changed-code quality check.
Performance
None that matters. This only runs once per Ghostty config import, which the user starts by hand. It is not on startup, rendering, terminal or polling paths. Measured old vs new with Node:
All 256 decimal indexes: 0.0012 ms -> 0.017 ms per pass
All 256 hex indexes: 0.003 ms -> 0.020 ms
Adversarial 100 KB keys (111...1x, 1_1_...x, 0xf_f_...g, +000...z): 0.12 ms each, linear, no backtracking blowup
No I/O, subprocesses or new allocations beyond the single regex match per palette entry.
Risk
Level: Low
This only affects how palette = N=#color lines are read during Ghostty import. The worst case is a palette entry that Ghostty accepts being skipped, which would leave the default color in that slot. A plain revert restores the old behavior. No saved settings format changes.
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Original fix by @Afloat16 in #50546. Their authorship is kept via Co-authored-by.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
… with a plus sign
Ghostty parses palette indexes with std.fmt.parseInt(u8, s, 0), which
accepts decimal, 0x/0o/0b prefixes, a leading sign and `_` between
digits. The importer used parseInt(s, 10), so every 0x/0o/0b index
landed on black and junk like `1wrong` overwrote red. Match Ghostty's
grammar exactly, strip `_` before the slot lookup, and keep rejecting
malformed indexes.
Fixes#50545
Co-authored-by: Afloat <[email protected]>
No actionable comments were generated in the recent review.
Walkthrough
The Ghostty palette importer now validates palette indices as complete decimal, hexadecimal, octal, or binary values. It removes permitted underscores before conversion and skips malformed indices, negative nonzero indices, and invalid colors. Tests cover supported index formats and malformed input.
Severity of issue fixed: Medium
Merge Risk: Minimal · up to 8269c
Ghostty palette indexes in hexadecimal, octal, binary and underscore-separated forms now map to the correct slots, and malformed indexes are skipped instead of overwriting valid colors. No merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: Ghostty palette indexes written in hex, octal, binary, or with a plus sign are now imported correctly. It matches the mapper.ts parser change and the radix tests. The …
Description check
The description follows the template. It has ELI5, What Changed, Why, Linked Issue (Fixes #50545), Visual Proof (N/A with reason), Testing, Performance (None, because...), Risk with level Low, and a c…
Linked Issues check
[#50545] requires that Ghostty palette indexes in decimal, 0x, 0o, and 0b notation map to their ANSI slots, and that invalid suffixes such as 1wrong not overwrite an earlier valid entry. The diff in…
Out of Scope Changes check
Whole-PR scope compares merge base cbc710a to head 8269c01. The changes are limited to src/main/ghostty/mapper.ts (regex constant, palette parsing branch) and src/main/ghostty/palette-index-import.tes…
Full details: Title check
Explanation
The title names the main change: Ghostty palette indexes written in hex, octal, binary, or with a plus sign are now imported correctly. It matches the mapper.ts parser change and the radix tests. The title is 86 characters, which is longer than ideal, but it stays specific and clear.
Full details: Description check
Explanation
The description follows the template. It has ELI5, What Changed, Why, Linked Issue (Fixes #50545), Visual Proof (N/A with reason), Testing, Performance (None, because...), Risk with level Low, and a completed Agent skill boundary checkbox. The Notes and Checklist sections are also present. Gaps: the Testing section does not list the platform as a required field beyond macOS, the AI Disclosure section is left as the template comment, and the lint/typecheck/test/build checklist item is unchecked. These are minor and the author notes CI will cover them.
Full details: Linked Issues check
Explanation
[#50545] requires that Ghostty palette indexes in decimal, 0x, 0o, and 0b notation map to their ANSI slots, and that invalid suffixes such as 1wrong not overwrite an earlier valid entry. The diff in src/main/ghostty/mapper.ts replaces Number.parseInt(idxStr, 10) with PALETTE_INDEX_RE. The regex accepts an optional sign, decimal, or 0x/0o/0b prefixes, and underscores only between digits. The index is then converted with Number(...) after underscores are removed. Malformed indexes hit continue and do not reach the assignment, so they cannot overwrite an earlier entry. The PR summary states that the regression tests in src/main/ghostty/palette-index-import.test.ts cover radix, signed, underscore, and malformed cases. I did not open that test file, and the PR checklist leaves the test commands unchecked, so test pass status is not independently confirmed. The change to the parser itself matches the issue's stated requirements. The issue's non-coding items (manual platform testing) do not apply.
Full details: Out of Scope Changes check
Explanation
Whole-PR scope compares merge base cbc710a to head 8269c01. The changes are limited to src/main/ghostty/mapper.ts (regex constant, palette parsing branch) and src/main/ghostty/palette-index-import.test.ts (regression tests). The regex, the sign handling, and the underscore stripping all serve the palette-index parsing objective of [#50545]. The negative-index skip matches u8 parsing semantics stated in the PR. Test additions support the same objective. No unrelated file or behavior change appears in the reviewed summary. The regex is case-insensitive for prefixes and hex digits. Whether Ghostty also accepts uppercase prefixes such as 0X was not verified against Ghostty source here. The PR reports probe results for 0X2, but that does not affect scope.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: c87db57c-5ed7-4a67-91f7-b2f1956c32ce
Commits
Reviewing files that changed from the base of the PR and between 0835b83 and 8269c01.
Files selected for processing: 2
src/main/ghostty/mapper.ts
src/main/ghostty/palette-index-import.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
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
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.
ELI5
Ghostty lets you number palette colors in hex, octal or binary (like
0x1for color 1). When Orca imported a Ghostty config, it read all of those as color 0, so they all landed on black and the colors you actually picked were lost. Now Orca reads those numbers the same way Ghostty does.What Changed
Number.parseInt(idx, 10).0x1,0o3and0b10all became0(black), and junk like1wrongwas read as1, overwriting a valid red.src/main/ghostty/mapper.tsmatches the index against the same grammar Ghostty uses (std.fmt.parseInt(u8, s, 0)insrc/terminal/color.zig): an optional+/-, decimal or0x/0o/0b(any letter case), and_only between digits. Underscores are stripped before the 0-15 slot lookup. Negative values other than-0are skipped, matching u8 parsing. Anything else is skipped and no longer overwrites a valid entry.Why
Before this change, imported Ghostty themes using non-decimal indexes came out wrong. Mirroring Ghostty's parser exactly, instead of adding a looser prefix check, keeps every index Ghostty accepts (including
+5,-0,1_5and0x0_e, whichparseIntalready handled) and rejects the ones Ghostty rejects.Linked Issue
Fixes #50545
Visual Proof
N/A. This is a config-import data fix with no new UI. Before/after is shown by the regression tests plus a probe that checks each index against Ghostty's own Zig
parseIntresults (0x1,0X2,0o3,0b101,1_0,0x0_f,-0,+0xF,1wrong,_1,1_,0x_1,0x100,256,-1,00x1,1e1, ...):1wrongoverwrites redTesting
src/main/ghostty/palette-index-import.test.ts(3 tests): radix prefixes map to the right ANSI slots; signed and underscore-separated indexes match Ghostty; malformed indexes (1wrong,-1,_1,1_,0x_1) don't override earlier entries. The radix and malformed tests fail on main.parsePaletteEntryon upstream main to confirm the grammar (std.fmt.parseInt(u8, trim(key, " \t"), 0)).Performance
None that matters. This only runs once per Ghostty config import, which the user starts by hand. It is not on startup, rendering, terminal or polling paths. Measured old vs new with Node:
111...1x,1_1_...x,0xf_f_...g,+000...z): 0.12 ms each, linear, no backtracking blowupNo I/O, subprocesses or new allocations beyond the single regex match per palette entry.
Risk
Level: Low
This only affects how
palette = N=#colorlines are read during Ghostty import. The worst case is a palette entry that Ghostty accepts being skipped, which would leave the default color in that slot. A plain revert restores the old behavior. No saved settings format changes.Agent skill upstream boundary
Notes
Original fix by @Afloat16 in #50546. Their authorship is kept via
Co-authored-by.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)