Skip to content

fix: update surface config on theme switch to restore ANSI palette#2685

Open
shelldonGuo wants to merge 1 commit intomanaflow-ai:mainfrom
shelldonGuo:fix-theme-switch-palette
Open

fix: update surface config on theme switch to restore ANSI palette#2685
shelldonGuo wants to merge 1 commit intomanaflow-ai:mainfrom
shelldonGuo:fix-theme-switch-palette

Conversation

@shelldonGuo
Copy link
Copy Markdown

@shelldonGuo shelldonGuo commented Apr 7, 2026

Problem

When switching between light and dark themes in cmux, existing terminal windows retain the ANSI color palette (colors 0–15) from the previous theme. This causes white text on a light background when switching from dark → light.

Root cause: applySurfaceColorScheme calls ghostty_surface_set_color_scheme, which only updates the scheme flag on the surface but does not re-apply the full ANSI palette. The palette (OSC 4, colors 0–15) stays from the previous theme.

New windows are unaffected because ghostty initializes their palette from the current config at surface creation time.

This is the cmux-side equivalent of the fix ghostty made in their standalone app (ghostty-org/ghostty#9360, shipped in ghostty 1.3.0): explicitly pushing the updated config to existing surfaces when the color scheme changes.

Fix

In applySurfaceColorScheme (GhosttyTerminalView.swift), call ghostty_surface_update_config(surface, config) before ghostty_surface_set_color_scheme. This pushes the complete config — including the correct ANSI palette for the new theme — to each existing surface.

// Push the current config to this surface before switching the color scheme.
// ghostty_surface_set_color_scheme alone only updates the scheme flag but does
// not re-apply the ANSI palette (OSC 4, colors 0-15) to the existing surface.
if let config = GhosttyApp.shared.config {
    ghostty_surface_update_config(surface, config)
}
ghostty_surface_set_color_scheme(surface, scheme)

Also fixes a Swift build error in ContentView.swift: protocol Panel used as an existential type must be written as any Panel.

Testing

  1. Open several terminal windows/panes
  2. Switch cmux theme from dark → light
  3. Verify existing windows now show dark text on light background (previously showed white text)
  4. Switch back to dark → verify existing windows show white text on dark background

Summary by cubic

Fixes theme switching so existing terminal surfaces update their ANSI palette, preventing white-on-light text after dark → light (and vice versa). Also resolves a Swift build error in ContentView.swift.

  • Bug Fixes
    • In GhosttyTerminalView.swift, call ghostty_surface_update_config(surface, config) before ghostty_surface_set_color_scheme(surface, scheme) to re-apply the ANSI palette on existing surfaces.
    • In ContentView.swift, change Panel existential to any Panel to fix the build.

Written for commit 1ba3da7. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed color palette application when switching between light and dark color schemes to ensure all ANSI colors display correctly.
  • Refactor

    • Updated method signature to use modern type system conventions.

When switching between light and dark themes, existing terminal surfaces
retained the ANSI color palette (colors 0-15) from the previous theme.
`ghostty_surface_set_color_scheme` only updates the scheme flag but does
not re-apply the full palette to the surface buffer.

Fix by calling `ghostty_surface_update_config` with the current app config
before `ghostty_surface_set_color_scheme` in `applySurfaceColorScheme`.
This pushes the complete palette for the new theme to each existing surface,
matching the behavior ghostty's standalone app introduced in PR #9360.

Also fix a Swift build error in ContentView.swift: protocol 'Panel' used
as an existential type must be written as 'any Panel'.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 7, 2026

Someone is attempting to deploy a commit to the Manaflow Team on Vercel.

A member of the Team first needs to authorize it.

@cubic-dev-ai
Copy link
Copy Markdown

cubic-dev-ai bot commented Apr 7, 2026

This review could not be run because your cubic account has exceeded the monthly review limit. If you need help restoring access, please contact contact@cubic.dev.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0f913b80-f644-4caa-b7fc-fcb8747b48bc

📥 Commits

Reviewing files that changed from the base of the PR and between 2669b6d and 1ba3da7.

📒 Files selected for processing (2)
  • Sources/ContentView.swift
  • Sources/GhosttyTerminalView.swift

📝 Walkthrough

Walkthrough

This PR updates Swift existential typing in ContentView and enhances Ghostty terminal color scheme switching by ensuring the full ANSI palette is reapplied via config update before switching color schemes.

Changes

Cohort / File(s) Summary
Protocol Type Update
Sources/ContentView.swift
Updated method parameter type from Panel to any Panel, enabling Swift existential protocol typing in the tmuxWorkspacePaneExactRect(for:in:) signature.
Color Scheme Configuration
Sources/GhosttyTerminalView.swift
Added ghostty_surface_update_config() call before color scheme switch in applySurfaceColorScheme(force:) to ensure full ANSI palette (OSC 4, colors 0–15) reapplication for light/dark theme changes.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly Related PRs

Poem

🐰 A protocol now wears existential dress,
While Ghostty's palette glows with freshness!
Config whispers before colors shift,
Light and dark receive their gift.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: updating surface config on theme switch to restore the ANSI palette.
Description check ✅ Passed The description provides clear problem statement, root cause analysis, the fix with code example, and testing steps. However, testing checklist items and review trigger block are not completed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 7, 2026

Greptile Summary

This PR fixes stale ANSI color palettes on existing terminal surfaces when switching between light/dark themes by calling ghostty_surface_update_config before ghostty_surface_set_color_scheme in applySurfaceColorScheme, mirroring ghostty's own fix in ghostty-org/ghostty#9360. It also corrects two Swift build errors where Panel was used as an existential type without the required any keyword in ContentView.swift.

Confidence Score: 5/5

Safe to merge — targeted fix on a non-hot code path with no blocking issues.

The fix is narrowly scoped to theme-change event paths (viewDidChangeEffectiveAppearance, attachSurface, viewDidMoveToWindow), well-commented, and mirrors the upstream Ghostty fix. The nil-guard on GhosttyApp.shared.config is a correct defensive pattern. Both changed files have straightforward, correct changes.

No files require special attention.

Important Files Changed

Filename Overview
Sources/GhosttyTerminalView.swift Adds ghostty_surface_update_config call before set_color_scheme to restore the full ANSI palette on theme switch; only runs on theme-change code paths, not hot typing paths.
Sources/ContentView.swift Fixes two Panel existential type syntax errors, updating bare Panel to any Panel in two function signatures.

Sequence Diagram

sequenceDiagram
    participant User
    participant GhosttyApp
    participant SurfaceView as WindowTerminalHostView
    participant Ghostty as libghostty

    User->>GhosttyApp: Switch theme (light ↔ dark)
    GhosttyApp->>SurfaceView: viewDidChangeEffectiveAppearance()
    SurfaceView->>SurfaceView: applySurfaceColorScheme()
    Note over SurfaceView: guard config != nil and scheme changed
    SurfaceView->>Ghostty: ghostty_surface_update_config(surface, config)
    Note over Ghostty: Pushes full config incl. ANSI palette (colors 0–15)
    SurfaceView->>Ghostty: ghostty_surface_set_color_scheme(surface, scheme)
    Note over Ghostty: Updates scheme flag on surface
    SurfaceView->>SurfaceView: appliedColorScheme = scheme
Loading

Reviews (1): Last reviewed commit: "fix: update surface config on theme swit..." | Re-trigger Greptile

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