Repository navigation
Unified theme pipeline + theme-derived semantic palette - #103
Merged
Merged
Conversation
Theme distribution had four coexisting patterns: AppDelegate enumerated eight consumers by hand, five controllers each hand-rolled updateAppearance boilerplate, the adapter exposed two overlapping sync helpers, and the workspace-creation panel pulled the theme once at show time — so a theme change while it was open left it stale (real bug), and every new window meant a three-step checklist plus an AppDelegate edit. ThemeDistributor is now the single pipeline: surfaces conform to ThemedSurface (default impl covers standard chrome), register once at creation, and are held weakly. Registration applies the current theme immediately, so lazily-created panels open already themed. propagateGhosttyTheme shrinks to broadcast + tmux; tmux deliberately stays outside the registry so key-window/full-screen repaints never thrash the tmux config. Behavior-preserving: existing background/effectiveBackground and appearance choices were migrated verbatim per consumer, including TerminalArea's no-appearance quirk.
SemanticPalette.derive maps a theme's ANSI table onto Mori's semantic status slots (error←1, success←2, warning←3, attention←11, info/active←4 — active shares blue with tmux's active-pane border on purpose) and runs every slot through a WCAG contrast guardrail: below 3.0:1 against the theme background, the color is nudged toward the foreground in 5% steps, capped at 60% so it still reads as the theme's color. Short palettes return nil so callers fall back to system colors. Plain RGB structs, no AppKit — the app target owns NSColor conversion at the boundary. Tested via a new MoriUITests executable target (mise run test:ui), including the honest case found while testing: Gruvbox Dark's red only reaches 2.69:1 and genuinely takes the nudge path.
MoriTokens.Color's six semantic slots (error/success/warning/attention/ info/active) become computed reads of MoriTheme.shared, a @mainactor @observable singleton defaulting to the exact system colors the tokens shipped with — un-applied, the UI paints pixel-for-pixel as before. Observation registers a dependency on any slot read during a SwiftUI body, so applying a derived palette re-renders every consumer with zero changes at the ~109 call sites. inactive/muted stay static: they are theme-independent neutrals. GhosttyThemeInfo now reports a missing ANSI palette as an empty array instead of 16 grays, so downstream derivation can tell 'no palette' apart from a genuinely gray theme; the only palette consumer (TmuxThemeApplicator) already guards indices and falls back safely.
MoriThemeBridge registers as a ThemedSurface: each broadcast converts the theme's background/foreground/ANSI colors to RGB, derives the semantic palette, and applies it to MoriTheme.shared — so the sidebar's status colors, PR badges, and selection accent wear the terminal theme's own colors, and the selection accent matches tmux's active-pane border (both palette[4]). Palette-less themes reset to system colors. Identical palettes are skipped so the key-window repaints that also broadcast never touch the store and re-render token-reading views for nothing.
# Conflicts: # CHANGELOG.md # CHANGELOG.zh-Hans.md
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.
What
Implements the theme plan (
2026-07-24-theme-derived-palette), four commits, one phase each:theme:one registry instead of hand-enumerated surfaces — Theme distribution had four coexisting patterns (AppDelegate fan-out to 8 consumers, five hand-rolledupdateAppearancemethods, two adapter sync helpers, and the creation panel pulling the theme at show time).ThemeDistributor+ThemedSurfaceis now the single pipeline; surfaces register once and are held weakly, registration applies the current theme immediately. Fixes a real bug: the cached workspace-creation panel kept its old skin if the theme changed while it was open. tmux deliberately stays outside the registry so key-window repaints never thrash tmux config. Behavior-preserving otherwise (per-consumer background/effectiveBackground choices migrated verbatim).ui:pure color math —SemanticPalette.derivemaps the theme's ANSI table onto semantic slots (error←1, success←2, warning←3, attention←11, info/active←4) with a WCAG guardrail: below 3.0:1 against the theme background, nudge toward the foreground in 5% steps, capped at 60%. NewMoriUITestsexecutable target (mise run test:ui, 34 assertions), wired into the aggregate.ui:observable token store —MoriTokens.Color's six semantic slots become computed reads ofMoriTheme.shared(@mainactor @observable). Defaults are the exact previous system colors; ~109 call sites unchanged; Observation re-renders consumers on apply. Missing ANSI palettes now surface as[]instead of 16 grays.theme:wiring —MoriThemeBridgeregisters as a consumer: convert → derive → apply (reset for palette-less themes; identical palettes skipped so focus-change repaints don't invalidate token views).Net effect: sidebar status colors, PR badges, and the selection accent wear the terminal theme's own colors, and the selection accent is the same blue as tmux's active-pane border. AGENTS.md's three-step new-window checklist is replaced by "conform
ThemedSurface+ register".Verification
mise run test— 7 targets green (incl. newtest:ui)CI=1 bash scripts/bundle.sh; unbundled.build/release/Morismoke-launched 6s and killed by exact PIDNotes for review
#cc241d) genuinely fails 3.0:1 against#282828and takes the nudge path — slightly brighter than the raw theme red is expected, not a bug (covered by tests).warning/attentioncan converge on themes where yellow ≈ bright yellow; both are attention-class signals and rarely co-occur. Upgrade path noted in the plan if it bothers in practice.