-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
iOS terminal: inherit the Mac's Ghostty theme instead of hardcoding Monokai #6119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lawrencecchen
wants to merge
14
commits into
main
Choose a base branch
from
feat-ios-inherit-mac-theme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
103c1d6
iOS terminal: inherit the Mac's Ghostty theme instead of hardcoding M…
lawrencecchen 34418b9
Stamp inherited theme on the cold-attach replay path too
lawrencecchen c67e205
Invalidate inherited-theme cache on surface reload; enforce 16-color …
lawrencecchen 50afea4
Clear inherited chrome background on a backgroundless full frame
lawrencecchen e781ad8
Emit a render-grid snapshot when the inherited theme changes
lawrencecchen adee376
Add DocC docs to MobileInheritedTerminalTheme public symbols
lawrencecchen ecc6316
Fix Swift 6 actor-isolation warning; refresh file-length budget
lawrencecchen 55c2850
Fix delta-survival test to use a real delta frame
lawrencecchen 86cf60a
Record inherited chrome background only for accepted frames
lawrencecchen fb7725b
Invalidate the mobile theme only on app-wide config reload
lawrencecchen 2e7f98b
Make inherited-theme shell tests run without the loopback harness
lawrencecchen 4cdb7f8
Merge remote-tracking branch 'origin/main' into feat-ios-inherit-mac-…
lawrencecchen ae713b1
Merge remote-tracking branch 'origin/main' into feat-ios-inherit-mac-…
lawrencecchen 63c347d
Merge remote-tracking branch 'origin/main' into feat-ios-inherit-mac-…
lawrencecchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
63 changes: 63 additions & 0 deletions
63
Packages/CMUXMobileCore/Sources/CMUXMobileCore/MobileInheritedTerminalTheme.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import Foundation | ||
|
|
||
| /// The Mac's resolved Ghostty terminal theme propagated to a paired phone so it | ||
| /// inherits the Mac's palette + default colors instead of a hardcoded Monokai. | ||
| /// | ||
| /// All colors are `#RRGGBB` hex strings. ``palette`` is the 16-color ANSI | ||
| /// palette (indices 0...15) or `nil` when the Mac could not resolve a full | ||
| /// 16-color palette (so the phone keeps its consistent built-in fallback). | ||
| /// ``foreground`` / ``background`` / ``cursor`` are `nil` when the user has not | ||
| /// configured that default (so the phone keeps its own default for that color, | ||
| /// and a program's live OSC 10/11/12 still wins). | ||
| /// | ||
| /// Resolving this walks the parsed Ghostty config and formats several NSColors, | ||
| /// so it must be computed off the per-keystroke render path and reused (cache it | ||
| /// and recompute only when the Ghostty config reloads) rather than rebuilt on | ||
| /// every render-grid export. | ||
| public struct MobileInheritedTerminalTheme: Equatable, Sendable { | ||
| /// The 16-color ANSI palette (indices 0...15) as `#RRGGBB` hex, or `nil` when | ||
| /// the Mac could not resolve a full 16-color palette. | ||
| public var palette: [String]? | ||
| /// The default foreground color as `#RRGGBB` hex, or `nil` when the user has | ||
| /// not configured one (the phone keeps its own default). | ||
| public var foreground: String? | ||
| /// The default background color as `#RRGGBB` hex, or `nil` when the user has | ||
| /// not configured one (the phone keeps its own default). | ||
| public var background: String? | ||
| /// The cursor color as `#RRGGBB` hex, or `nil` when the user has not | ||
| /// configured one (the phone keeps its own default). | ||
| public var cursor: String? | ||
|
|
||
| /// Creates an inherited theme. Each color is an optional `#RRGGBB` hex string; | ||
| /// see the property docs for what `nil` means per field. | ||
| public init( | ||
| palette: [String]? = nil, | ||
| foreground: String? = nil, | ||
| background: String? = nil, | ||
| cursor: String? = nil | ||
| ) { | ||
| self.palette = palette | ||
| self.foreground = foreground | ||
| self.background = background | ||
| self.cursor = cursor | ||
| } | ||
| } | ||
|
|
||
| extension MobileTerminalRenderGridFrame { | ||
| /// Stamp the Mac's inherited theme onto a full snapshot. The palette always | ||
| /// replaces the frame's (libghostty's grid JSON never carries it); the | ||
| /// default colors only backfill where the program has not already set a | ||
| /// dynamic default (OSC 10/11/12), so a running program's live colors win | ||
| /// over the static theme. Meaningful only on a full frame; a delta drops the | ||
| /// theme fields, so callers should skip this for deltas. | ||
| public mutating func applyInheritedTheme(_ theme: MobileInheritedTerminalTheme) { | ||
| // Enforce the same 16-entry invariant the frame initializer applies, so a | ||
| // partial palette never reaches OSC 4 (which would mix inherited and | ||
| // fallback colors). A non-16 palette is dropped, keeping the phone's | ||
| // consistent built-in fallback. | ||
| terminalPalette = (theme.palette?.count == 16) ? theme.palette : nil | ||
| if terminalForeground == nil { terminalForeground = theme.foreground } | ||
| if terminalBackground == nil { terminalBackground = theme.background } | ||
| if terminalCursorColor == nil { terminalCursorColor = theme.cursor } | ||
| } | ||
| } | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate palette entry format before accepting inherited palette.
At Line 58, the gate only checks
count == 16. That still admits malformed entries, and replay later skips invalid entries individually, which can leave a partially updated ANSI palette (stale slots from prior state). Please normalize atomically: accept the palette only when all 16 entries are valid#RRGGBB, otherwise drop the whole palette tonil.Proposed fix
public mutating func applyInheritedTheme(_ theme: MobileInheritedTerminalTheme) { - terminalPalette = (theme.palette?.count == 16) ? theme.palette : nil + terminalPalette = Self.normalizedTerminalPalette(theme.palette) if terminalForeground == nil { terminalForeground = theme.foreground } if terminalBackground == nil { terminalBackground = theme.background } if terminalCursorColor == nil { terminalCursorColor = theme.cursor } } + +private static func normalizedTerminalPalette(_ palette: [String]?) -> [String]? { + guard let palette, palette.count == 16 else { return nil } + let isValidHex: (String) -> Bool = { value in + guard value.hasPrefix("#"), value.count == 7 else { return false } + return Int(value.dropFirst(), radix: 16) != nil + } + return palette.allSatisfy(isValidHex) ? palette : nil +}🤖 Prompt for AI Agents