Skip to content

feat(web): system theme option — follow the OS prefers-color-scheme (stretch of #67) - #90

Open
dchaudhari7177 wants to merge 2 commits into
burakgon:mainfrom
dchaudhari7177:feat/system-theme
Open

feat(web): system theme option — follow the OS prefers-color-scheme (stretch of #67)#90
dchaudhari7177 wants to merge 2 commits into
burakgon:mainfrom
dchaudhari7177:feat/system-theme

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

The stretch item from #67 ("a fourth system option that follows prefers-color-scheme"), as the separate PR the issue invited.

Builds on #89 — the light-theme PR. This branch contains #89's commit; the net new diff is the last commit (feat(web): system theme option). Happy to rebase once #89 lands.

pwa/theme.ts — the stored preference and the rendered palette are now distinct types: ThemeName (dark | oled | light, what tokens.css/xterm can render) vs ThemePreference (ThemeName | "system"). resolveTheme() maps "system" to light/dark via (prefers-color-scheme: light), using the same defensive matchMedia guard as AppLayout.useIsDesktop (jsdom/SSR → dark). watchSystemTheme() re-applies and re-announces rc-theme-change when the OS scheme flips — but only while the preference is "system", so a concrete choice never gets overridden.

main.tsx — starts the watcher immediately after the boot applyTheme, so a daylight/night OS switch restyles the app (and an open terminal, which re-reads its palette on rc-theme-change) live, no reload.

SettingsPanel.tsx — a fourth System option in the Theme select; still applies instantly.

Tests — extends theme.test.ts (8 passing): "system" round-trips and resolves per a stubbed prefers-color-scheme; without matchMedia it falls back to dark instead of crashing; the OS-flip watcher announces only while the preference is system (vi.stubGlobal matchMedia stub with a change-listener registry, the repo's existing idiom).

Verificationpnpm typecheck clean; theme tests 8/8. End-to-end in a real browser: with the stored preference "system", booting under an OS light scheme paints paper (data-theme="light", --bg #f6f6f7) and under an OS dark scheme paints near-black with the theme-color meta mirrored (#0a0a0b, attribute removed).

Three-way theme choice in Settings (Dark / True black / Light),
replacing the OLED checkbox:

- theme.ts: ThemeName gains "light"; stored-value validation keeps
  unknown values falling back to dark; applyTheme sets data-theme for
  any non-default theme.
- tokens.css: a [data-theme=light] block — paper surfaces, ink text,
  darkened hairlines; the coral accent shifts to its deep value for
  contrast on paper; warn/err darkened for AA. The code card stays a
  dark panel deliberately.
- TerminalView: light mode swaps the FULL xterm palette (One
  Light-derived), not just the background — the dark ANSI ramp would
  be unreadable on paper. Live switch keeps working via rc-theme-change.
- theme.test.ts extended for the new value, fallback, and meta mirror.

Closes burakgon#67
- theme.ts: ThemePreference = ThemeName | "system"; resolveTheme() maps
  "system" to light/dark via (prefers-color-scheme: light) with the AppLayout
  matchMedia guard idiom (jsdom/SSR falls back to dark); watchSystemTheme()
  re-applies + re-announces rc-theme-change on OS flips only while the
  preference is "system".
- main.tsx: start the watcher right after the boot applyTheme.
- SettingsPanel: fourth "System" option in the Theme select.
- TerminalView: terminalTheme() resolves the preference, so an open terminal
  follows an OS scheme flip live via the re-fired rc-theme-change.
- Tests: system round-trip + no-matchMedia fallback, OS-flip announce gating
  (vi.stubGlobal matchMedia stub with a change-listener registry).

Stretch item from burakgon#67
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