Skip to content

fix(tui): detect Windows system dark mode via registry#36249

Open
JohnXu22786 wants to merge 1 commit into
anomalyco:devfrom
JohnXu22786:fix-win-theme-detection
Open

fix(tui): detect Windows system dark mode via registry#36249
JohnXu22786 wants to merge 1 commit into
anomalyco:devfrom
JohnXu22786:fix-win-theme-detection

Conversation

@JohnXu22786

@JohnXu22786 JohnXu22786 commented Jul 10, 2026

Copy link
Copy Markdown

Issue for this PR

Fixes #36252

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

On Windows 11 Terminal the terminal background colour (OSC 11) stays the same regardless of the system dark/light theme. Only the title bar changes. opencode's terminalMode() only reads the background colour, so it always returns the same value and the TUI never switches.

This PR adds a Windows registry fallback:

  • win32SystemTheme() in terminal-win32.ts queries HKCU\...\Personalize\AppsUseLightTheme (0 = dark, 1 = light).
  • resolveSystemTheme() in theme.tsx overrides the terminal-detected mode with the registry value on win32.
  • A 3-second poll on win32 catches dynamic theme toggles while the TUI is running, then calls apply() to switch.

On non-Windows nothing changes. If the registry key is absent (Windows 8 or earlier) behaviour also stays unchanged — it falls back to the terminal background detection.

How did you verify your code works?

  • Unit tests for win32SystemTheme() pass on Windows (3 tests, 0 fail)
  • All 8 existing theme tests pass with no regression
  • Ran from packages/tui with bun test test/win32-theme.test.ts and bun test test/theme.test.ts

Screenshots / recordings

N/A — terminal UI change, not visual UI.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

On Windows 11 Terminal the buffer background (OSC 11) is independent
of the system dark/light theme.  The title bar follows the system
theme but the background colour queried via \e]11;?\e\\ does not
change, so opencode's terminalMode() always returns the same value
and the TUI never switches.

Fix this by reading the Windows registry key
  HKCU\...\Themes\Personalize\AppsUseLightTheme
on win32.  Two changes:

- In resolveSystemTheme(): override the mode with the registry value
  when running on Windows.  The registry is authoritative because
  the terminal background colour is not a reliable signal.

- Poll the registry every 3 s to catch dynamic system-theme changes
  that happen while the TUI is already running.  The interval is
  unref'd so it does not keep the process alive.
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.

TUI dark/light mode does not follow Windows system theme

1 participant