feat: add dynamic theme changes#144
Open
brianegan wants to merge 1 commit into
Open
Conversation
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>
Author
|
Resolves #125 |
11 tasks
5 tasks
diegosouzapw
added a commit
to diegosouzapw/ghostty-web
that referenced
this pull request
May 23, 2026
…heme Today, the theme passed to the Terminal constructor is captured at open() time and never changes. Apps that need to switch themes at runtime (light/ dark toggle, accessibility preference change, multi-window state) had to dispose the Terminal and recreate it — which destroys scrollback, selection, and focus. This commit adds a runtime theme change path: - Public API: `Terminal.setTheme(theme)` updates the theme atomically and triggers a single render. Equivalent to assigning `options.theme = ...` via the existing options Proxy (also supported). - WASM bridge: new exports `terminal_set_theme` (full theme update) and the renderer is invalidated so the next frame redraws every cell with the new palette / background. - The renderer's color cache (introduced in older PRs) is cleared on theme change so old `rgb(...)` strings don't outlive their palette. Adds 12 new tests covering: full-theme update mid-session, ANSI palette update, default-color fallback when theme omits ansi colors, no-op on identical theme, render scheduling, options-proxy compatibility. Excludes the binary `ghostty-vt.wasm` from the upstream diff (CI / local `bun run build:wasm` rebuilds it from the updated patch). Co-authored-by: Brian Egan <brian.egan@verygood.ventures> Inspired-by: coder#144
diegosouzapw
added a commit
to diegosouzapw/ghostty-web
that referenced
this pull request
May 23, 2026
…heme Today, the theme passed to the Terminal constructor is captured at open() time and never changes. Apps that need to switch themes at runtime (light/ dark toggle, accessibility preference change, multi-window state) had to dispose the Terminal and recreate it — which destroys scrollback, selection, and focus. This commit adds a runtime theme change path: - Public API: `Terminal.setTheme(theme)` updates the theme atomically and triggers a single render. Equivalent to assigning `options.theme = ...` via the existing options Proxy (also supported). - WASM bridge: new exports `terminal_set_theme` (full theme update) and the renderer is invalidated so the next frame redraws every cell with the new palette / background. - The renderer's color cache (introduced in older PRs) is cleared on theme change so old `rgb(...)` strings don't outlive their palette. Adds 12 new tests covering: full-theme update mid-session, ANSI palette update, default-color fallback when theme omits ansi colors, no-op on identical theme, render scheduling, options-proxy compatibility. Excludes the binary `ghostty-vt.wasm` from the upstream diff (CI / local `bun run build:wasm` rebuilds it from the updated patch). Co-authored-by: Brian Egan <brian.egan@verygood.ventures> Inspired-by: coder#144
diegosouzapw
added a commit
to diegosouzapw/ghostty-web
that referenced
this pull request
May 23, 2026
…heme (#14) Today, the theme passed to the Terminal constructor is captured at open() time and never changes. Apps that need to switch themes at runtime (light/ dark toggle, accessibility preference change, multi-window state) had to dispose the Terminal and recreate it — which destroys scrollback, selection, and focus. This commit adds a runtime theme change path: - Public API: `Terminal.setTheme(theme)` updates the theme atomically and triggers a single render. Equivalent to assigning `options.theme = ...` via the existing options Proxy (also supported). - WASM bridge: new exports `terminal_set_theme` (full theme update) and the renderer is invalidated so the next frame redraws every cell with the new palette / background. - The renderer's color cache (introduced in older PRs) is cleared on theme change so old `rgb(...)` strings don't outlive their palette. Adds 12 new tests covering: full-theme update mid-session, ANSI palette update, default-color fallback when theme omits ansi colors, no-op on identical theme, render scheduling, options-proxy compatibility. Excludes the binary `ghostty-vt.wasm` from the upstream diff (CI / local `bun run build:wasm` rebuilds it from the updated patch). Inspired-by: coder#144 Co-authored-by: Brian Egan <brian.egan@verygood.ventures>
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.
Summary
ghostty_terminal_set_colorsWASM export that updates terminal colors at runtime and forces a full redrawterminal.options.theme = newThemeto merge partial themes, update the renderer, and sync WASM terminal colorsbackgroundpreserves all other colors)Usage
Changes
patches/ghostty-wasm-api.patchsetColors()Zig function,force_full_redrawflag onTerminalWrapper, render state reset on color changeghostty-vt.wasmghostty_terminal_set_colorsexportlib/types.tsghostty_terminal_set_colorsto WASM exports interfacelib/ghostty.tssetColors()method toGhosttyTerminalclasslib/terminal.tshandleOptionChange('theme')now merges, updates renderer + WASM; addedcurrentThemeaccumulator andbuildThemeColorsConfig()helperlib/terminal.test.tsTest plan
null/undefined/{}restores defaultsopen()is applied correctlyneedsFullRedraw()returns true)bun run typecheck && bun testpass (343 tests, 0 failures)🤖 Generated with Claude Code