iOS terminal: inherit the Mac's Ghostty theme instead of hardcoding Monokai
Inherit the Mac's Ghostty theme on iOS instead of hardcoding Monokai
The iOS terminal hardcoded the Monokai theme. The phone's local libghostty surface was built with a fixed background = #272822 + palette 0..15 = <monokai>, and the chrome (composer/input-accessory bar, pre-output placeholder) used a hardcoded Monokai color. If a Mac ran a different Ghostty theme, the phone's ANSI-indexed colors and chrome did not match it.
What already propagated: the render-grid replay sent the Mac's runtime default foreground/background/cursor as OSC 10/11/12, so dynamic default fg/bg followed. What did not: the 16-color ANSI palette, the configured (non-dynamic) theme defaults, and the UI chrome. Indexed output and chrome stayed Monokai regardless of the Mac's theme.
The fix
The Mac now sends its resolved Ghostty theme on each full render-grid frame, and iOS applies it:
- Frame: added
terminal_palette(16#RRGGBBentries, indices 0..15) toMobileTerminalRenderGridFrame, alongside the existingterminal_foreground/background/cursor. Additive, carried only on full snapshots, nil'd on deltas (mirrors the existing color fields). - Mac producer (
TerminalSurface.mobileRenderGridFrame): stamps the resolved palette + default fg/bg/cursor from the same parsedGhosttyConfigthe Mac renders with. libghostty's C config getter cannot return the palette array, so it reads the parsed Swift config directly. Defaults only backfill where the program has not set a runtime OSC 10/11/12, so a running program's live colors still win. The theme is resolved once and cached, invalidated on.ghosttyConfigDidReload, so the config-parse + color-format work stays off the per-keystroke render path. - Replay: emits the inherited palette as OSC 4 in the full-snapshot byte stream, so the phone's surface resolves ANSI-indexed colors against the Mac's theme.
- Chrome: the composer/input-accessory bar and the pre-output placeholder now follow the inherited background (recorded per surface in
MobileShellComposite), not a constant. - Monokai stays ONLY as the explicit pre-first-frame fallback (the brief window before a frame arrives, and unpaired/preview surfaces), commented as such.
- Cold-attach: the
mobile.terminal.replay/ scroll-prefetch path (the first snapshot a newly mounted iOS surface gets) stamps the same cached theme, so the phone is themed on its first frame, not only after a later live event. - Live theme changes:
MobileTerminalRenderObservertracks a theme signature and forces a full frame when the theme changes, and config-reload invalidation (both app-level.ghosttyConfigDidReloadand the surface-only reload path) drops the cached theme AND schedules a render-grid emit, so a light↔dark switch or edited Ghostty config updates an already-attached phone even on an idle terminal, without waiting for a cold re-attach. A full snapshot with no background clears the inherited chrome color so it never goes stale.
Per-Mac correctness
The theme rides each Mac's render-grid frames, so it is per-surface/per-connection. Switching between paired Macs or workspaces shows each Mac's own theme; nothing caches one global theme across Macs.
Tests
- Frame round-trip + replay: palette encodes/decodes, OSC 4 emitted for all 16 indices on a full frame, partial palette (<16) dropped, palette dropped on deltas,
applyInheritedThemebackfills defaults but a program's live OSC color wins. - Shell: inherited background recorded from a full frame and survives delta frames (
MobileShellInheritedThemeTests). swift testCMUXMobileCore green (110 tests). macOS app build, iOS simulator build, and CmuxMobileShell build all succeed.
Verified vs UNVERIFIED
Verified: both-surface compile (macOS app + iOS simulator), CMUXMobileCore unit suite, the producer reads the resolved palette and the replay emits OSC 4. UNVERIFIED: the live on-device visual (a non-Monokai-themed Mac paired to a phone, showing the phone inherit that exact palette + chrome). That needs the full paired-device flow and iOS device signing creds that are unavailable in this environment; it is left for dogfood with a real paired iPhone.
🤖 Generated with Claude Code
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.
[!NOTE]
Medium Risk
Cross-cutting mobile terminal sync (wire format, VT replay, Mac export, iOS chrome) with theme-cache invalidation edge cases; well-tested but visual pairing is unverified on device.
Overview
Paired iOS terminals no longer stay on hardcoded Monokai for ANSI colors and surrounding chrome. Full mobile render-grid snapshots now carry the Mac’s resolved Ghostty theme: a 16-entry terminal_palette plus default fg/bg/cursor, stamped from parsed GhosttyConfig on export and replayed on the phone as OSC 4 (palette) and existing OSC 10/11/12 (defaults). Runtime program colors still win where already set; partial palettes are dropped so the phone never mixes inherited and fallback entries.
The Mac caches theme resolution off the hot path (MobileTerminalRenderObserver), invalidates on .ghosttyConfigDidReload, and forces a full frame when the theme signature changes so idle terminals still push updates. Cold-attach replay uses the same cache. On iOS, MobileShellComposite records inherited background only for delivered frames and drives the input-accessory bar / placeholder via GhosttySurfaceView; Monokai remains only the pre-first-frame fallback.
Reviewed by Cursor Bugbot for commit 63c347d7d95a38408579b8e379845c013728473c. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
iOS now inherits the Mac’s Ghostty theme so the 16‑color palette, default colors, and chrome match the Mac from the first frame and stay in sync on theme changes. Background recording is guarded and clears on backgroundless full frames so chrome never shows stale colors after unmounts or config updates.
-
New Features
- Added
terminal_palette(16#RRGGBB) toMobileTerminalRenderGridFrame; replay emits OSC 4 for all 16 entries before OSC 10/11/12; dropped on deltas and if not exactly 16 entries. - Mac stamps the resolved theme via
TerminalSurface.resolvedTerminalTheme; cached inMobileTerminalRenderObserver; applied on live emits and cold‑attach replay; program OSC 10/11/12 still win. - iOS chrome (input bar and pre‑output placeholder) adopts the inherited background; Monokai is the pre‑first‑frame fallback; a backgroundless full frame clears the chrome color.
- Theme cache invalidates on app‑wide
.ghosttyConfigDidReload; a theme signature forces a full snapshot and schedules a global emit so attached phones update even when idle or in the background.
- Added
-
Bug Fixes
- Record the inherited background only when a frame is accepted into the output stream, preventing stale chrome after unregister/remount.
- Enforce a strict 16‑entry palette; deltas omit the palette to avoid mixing inherited and fallback colors.
- Delta‑survival test uses a real delta; inherited‑theme shell tests run without the loopback harness.
Summary by CodeRabbit
- New Features
- iOS terminal surfaces now inherit Mac theme details: optional 16-color ANSI palette plus default foreground/background/cursor, and matching UI chrome/input-accessory background.
- Full snapshots replay the inherited 16-color palette via OSC 4 when available.
- Bug Fixes
- Theme and palette updates now reliably trigger refreshed full snapshots on iOS, preventing stale colors after config changes.
- Inherited chrome background persists across delta frames and clears when a later full snapshot omits background.
- Tests
- Added coverage for palette inheritance rules, OSC 4 replay behavior, JSON round-tripping, and full vs. delta snapshot differences.