Skip to content

Unified theme pipeline + theme-derived semantic palette - #103

Merged
vaayne merged 5 commits into
mainfrom
theme/unified-pipeline
Jul 24, 2026
Merged

vaayne merged 5 commits into
mainfrom
theme/unified-pipeline

Conversation

@vaayne

@vaayne vaayne commented Jul 24, 2026

Copy link
Copy Markdown
Owner

What

Implements the theme plan (2026-07-24-theme-derived-palette), four commits, one phase each:

  1. theme: one registry instead of hand-enumerated surfaces — Theme distribution had four coexisting patterns (AppDelegate fan-out to 8 consumers, five hand-rolled updateAppearance methods, two adapter sync helpers, and the creation panel pulling the theme at show time). ThemeDistributor + ThemedSurface is 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).
  2. ui: pure color math — SemanticPalette.derive maps 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%. New MoriUITests executable target (mise run test:ui, 34 assertions), wired into the aggregate.
  3. ui: observable token store — MoriTokens.Color's six semantic slots become computed reads of MoriTheme.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.
  4. theme: wiring — MoriThemeBridge registers 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. new test:ui)
  • Release builds of both products; CI=1 bash scripts/bundle.sh; unbundled .build/release/Mori smoke-launched 6s and killed by exact PID
  • Remaining manual checks (please eyeball before merge): theme switch + reload re-derives sidebar colors and matches the tmux active border; split-theme light/dark flip re-derives; a palette-less config falls back to system colors

Notes for review

  • Gruvbox Dark's red (#cc241d) genuinely fails 3.0:1 against #282828 and takes the nudge path — slightly brighter than the raw theme red is expected, not a bug (covered by tests).
  • warning/attention can 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.
  • Independent of PR Default terminal padding + quieter sidebar #102 (branched from main; only shared file is the changelogs, trivial merge).

vaayne added 5 commits July 24, 2026 11:16
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
@vaayne
vaayne merged commit 5f28658 into main Jul 24, 2026
@vaayne
vaayne deleted the theme/unified-pipeline branch July 24, 2026 03:43
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