Repository navigation
feat(ghostty): resolve theme references during config import - #7126
Conversation
`theme = <name>` is how most Ghostty configs pick their colors, but the importer treated the key as unsupported and silently dropped the entire palette. Resolve the referenced theme file and merge its colors as defaults, mirroring Ghostty's own precedence: - Search user themes first (XDG, then the native macOS dir), then the bundled themes inside the Ghostty install, and parse the file with the existing parseGhosttyConfig (theme files are plain config subsets). - Explicit config keys win over theme values; config palette entries are appended after the theme's so per-index overrides apply naturally. - Only color-bearing keys may flow from a theme into the import, a theme file cannot smuggle font/window settings past the user's config. - Theme names containing path separators are rejected (no traversal), files over 256 KB are ignored, and light:/dark: pairs plus unresolvable names surface as annotated unsupportedKeys instead of vanishing.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughChangesThis change adds Ghostty theme reference support. A new module discovers theme search directories with platform-specific and environment-based overrides, then resolves theme files into a whitelisted set of color keys with size and path safety checks. Ghostty config preview now applies 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
Co-authored-by: Orca <[email protected]>
Jinwoo-H
left a comment
There was a problem hiding this comment.
Thanks, this is a good fix. I added one maintainer follow-up before landing:
- aligned theme resolution with Ghostty lookup details: absolute paths, GHOSTTY_RESOURCES_DIR, and invalid user-theme shadowing
- split focused theme import coverage out of the general importer test
- verified the Electron Settings import flow end to end
Validated with Ghostty unit tests, typecheck, integration lint on current main, and Electron e2e coverage for preview/apply/persisted settings.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/ghostty/theme-resolution.ts (1)
97-120: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winUndocumented "no fallthrough on invalid" behavior — verify against Ghostty semantics.
When a relative-name candidate resolves to a path that exists but is invalid (not a regular file, or oversized), the loop returns
nullimmediately instead of continuing to probe the remaining search directories (Line 115-117). This "shadowing" behavior is intentional per the test suite, but it's a subtle design choice with no inline explanation, and it's unclear whether this matches real Ghostty's fallback semantics when a named theme candidate exists but can't be read (e.g., a directory or file-system error) — Ghostty's own file-open logic might simply move on to the next search directory in that case.As per coding guidelines,
**/*.{ts,tsx,js,jsx}: "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."📝 Suggested comment
if (result.status === 'invalid') { + // Why: an invalid match "shadows" later search dirs — we don't want to + // silently fall back to a bundled theme when the user's named theme + // exists but is unreadable/oversized. return null }Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c1da576b-e52f-4f7e-9824-1c398f0e9390
📒 Files selected for processing (4)
src/main/ghostty/index.tssrc/main/ghostty/theme-import.test.tssrc/main/ghostty/theme-resolution.test.tssrc/main/ghostty/theme-resolution.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/ghostty/index.ts
Co-authored-by: Orca <[email protected]>
…i#7126) * feat(ghostty): resolve theme references during config import `theme = <name>` is how most Ghostty configs pick their colors, but the importer treated the key as unsupported and silently dropped the entire palette. Resolve the referenced theme file and merge its colors as defaults, mirroring Ghostty's own precedence: - Search user themes first (XDG, then the native macOS dir), then the bundled themes inside the Ghostty install, and parse the file with the existing parseGhosttyConfig (theme files are plain config subsets). - Explicit config keys win over theme values; config palette entries are appended after the theme's so per-index overrides apply naturally. - Only color-bearing keys may flow from a theme into the import, a theme file cannot smuggle font/window settings past the user's config. - Theme names containing path separators are rejected (no traversal), files over 256 KB are ignored, and light:/dark: pairs plus unresolvable names surface as annotated unsupportedKeys instead of vanishing. * fix(ghostty): align theme resolution with Ghostty lookup Co-authored-by: Orca <[email protected]> * test: stabilize ghostty import CI coverage Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Jinwoo-H <[email protected]> Co-authored-by: Orca <[email protected]>
Summary
theme = <name>is the most common way Ghostty configs pick their colors, but the importer currently treats the key as unsupported — so for a config like:the import silently drops the entire palette and only the font settings survive. This PR resolves the referenced theme file and merges its colors into the import, mirroring Ghostty's own precedence.
How it works
theme-resolution.tssearches themes in Ghostty's lookup order: user themes ($XDG_CONFIG_HOME/ghostty/themesor~/.config/ghostty/themes, plus the native macOS app-support dir) shadow the bundled themes inside the Ghostty install (Ghostty.app/Contents/Resources/ghostty/themeson macOS,/usr/share/ghostty/themes+/usr/local/share/ghostty/themeson Linux). Theme files are plain config subsets, so the existingparseGhosttyConfigparses them as-is.paletteentries are appended after the theme's so per-index overrides apply naturally through the existing mapper.theme (theme file not found)andlight:X,dark:Ypairs astheme (light:/dark: pairs not supported)inunsupportedKeys, instead of vanishing silently.Test plan
vitest run src/main/ghostty/— 125/125 passoxlintandtsgo --noEmit -p config/tsconfig.node.jsoncleantheme = Tomorrow Night Bright(palette previously lost entirely on import)Related: #7125 (adjust-cell-height / dual-value paddings — independent branches, no overlap)