Skip to content

feat: add dynamic theme changes#144

Open
brianegan wants to merge 1 commit intocoder:mainfrom
brianegan:feat/dynamic-theme-changes
Open

feat: add dynamic theme changes#144
brianegan wants to merge 1 commit intocoder:mainfrom
brianegan:feat/dynamic-theme-changes

Conversation

@brianegan
Copy link
Copy Markdown

Summary

  • Add ghostty_terminal_set_colors WASM export that updates terminal colors at runtime and forces a full redraw
  • Wire up terminal.options.theme = newTheme to merge partial themes, update the renderer, and sync WASM terminal colors
  • Existing content re-renders instantly — cells with ANSI palette/default colors pick up the new theme; explicit RGB cells remain unchanged
  • Support partial theme updates that accumulate (e.g. setting only background preserves all other colors)

Usage

// Full theme swap
terminal.options.theme = { background: '#000', foreground: '#fff', red: '#ff0000' };

// Partial update — only changes background, keeps everything else
terminal.options.theme = { background: '#1a1a2e' };

// Reset to defaults
terminal.options.theme = {};

Changes

File Change
patches/ghostty-wasm-api.patch New setColors() Zig function, force_full_redraw flag on TerminalWrapper, render state reset on color change
ghostty-vt.wasm Rebuilt with ghostty_terminal_set_colors export
lib/types.ts Added ghostty_terminal_set_colors to WASM exports interface
lib/ghostty.ts Added setColors() method to GhosttyTerminal class
lib/terminal.ts handleOptionChange('theme') now merges, updates renderer + WASM; added currentTheme accumulator and buildThemeColorsConfig() helper
lib/terminal.test.ts 12 new tests covering full/partial/reset/accumulation/ANSI re-resolution/RGB unchanged/redraw trigger

Test plan

  • Full theme change updates renderer and WASM colors
  • Partial theme updates preserve previous customizations
  • Successive partial updates accumulate correctly
  • Reset to null/undefined/{} restores defaults
  • Theme set before open() is applied correctly
  • ANSI palette color cells re-resolve after theme change
  • Explicit RGB color cells remain unchanged
  • Theme change triggers full redraw (needsFullRedraw() returns true)
  • Invalid color values do not crash
  • Default fg/bg cells update after theme change
  • bun run typecheck && bun test pass (343 tests, 0 failures)

🤖 Generated with Claude Code

Enable runtime theme changes via `terminal.options.theme = newTheme`
without restarting the terminal. All existing content re-renders
instantly with the new colors.

- Add `ghostty_terminal_set_colors` WASM export that updates terminal
  colors and forces a full redraw
- Wire up `handleOptionChange('theme')` to merge partial themes,
  update the renderer, and sync WASM terminal colors
- Support partial theme updates that accumulate (e.g. setting only
  background preserves all other colors)
- Cells with ANSI palette/default colors re-resolve; explicit RGB
  cells remain unchanged

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brianegan
Copy link
Copy Markdown
Author

Resolves #125

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.

1 participant