Skip to content

fix(ghostty): import palette indexes written in hex, octal, binary or with a plus sign - #50608

Merged
nwparker merged 1 commit into
mainfrom
bugbash/pr-50546
Nov 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/pr-50546

Conversation

@nwparker

@nwparker nwparker commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

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.

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 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]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed [#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 Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • 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.

Finishing Touches
Fix failing CI checks

  • Commit to this branch
  • Create a new PR

@nwparker nwparker closed this Nov 27, 2026
@nwparker nwparker reopened this Nov 27, 2026
@nwparker
nwparker merged commit a567ac6 into main Nov 27, 2026
148 of 152 checks passed
@nwparker
nwparker deleted the bugbash/pr-50546 branch November 27, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Ghostty hexadecimal, octal and binary palette indexes map to black

1 participant