fix(tui): detect Windows system dark mode via registry#36249
Open
JohnXu22786 wants to merge 1 commit into
Open
fix(tui): detect Windows system dark mode via registry#36249JohnXu22786 wants to merge 1 commit into
JohnXu22786 wants to merge 1 commit into
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
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.
e11a25c to
74fa479
Compare
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.
Issue for this PR
Fixes #36252
Type of change
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()interminal-win32.tsqueriesHKCU\...\Personalize\AppsUseLightTheme(0 = dark, 1 = light).resolveSystemTheme()intheme.tsxoverrides the terminal-detected mode with the registry value on win32.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?
win32SystemTheme()pass on Windows (3 tests, 0 fail)packages/tuiwithbun test test/win32-theme.test.tsandbun test test/theme.test.tsScreenshots / recordings
N/A — terminal UI change, not visual UI.
Checklist