mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-25 04:55:58 +03:00
[PR #657] [MERGED] feat(renderer): add Mode 2031 dark/light theme detection #690
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#690
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/anomalyco/opentui/pull/657
Author: @kavhnr
Created: 2/9/2026
Status: ✅ Merged
Merged: 2/10/2026
Merged by: @kommander
Base:
main← Head:feat/mode-2031📝 Commits (2)
258bf2cfeat(renderer): add Mode 2031 dark/light theme detection846e043Merge branch 'main' into feat/mode-2031📊 Changes
3 files changed (+41 additions, -3 deletions)
View changed files
📝
packages/core/src/renderer.ts(+25 -0)📝
packages/core/src/types.ts(+3 -0)📝
packages/core/src/zig/terminal.zig(+13 -3)📄 Description
https://github.com/user-attachments/assets/b6b47db0-beb5-4c8d-8147-df6724dbf823
Summary
Adds support for the Mode 2031 terminal protocol, enabling automatic dark/light theme detection and live reactivity to OS appearance changes.
Supersedes #654 (closed) — this is a clean rewrite addressing the review feedback to move setup/shutdown into the Zig native layer.
What this does
CSI ? 2031 h) duringenableDetectedFeatures()in terminal.zigCSI ? 996 n) on startupCSI ? 997 ; 1 n(dark) /CSI ? 997 ; 2 n(light) responses via a newthemeModeHandlerin the input handler pipelinetheme_modeevent on the renderer when the mode changesthemeModegetter returningThemeMode | nullCSI ? 2031 l) on destroy viaresetState()ThemeModetype fromtypes.tsand addstheme_modetoRendererEventsSupported terminals
Unsupported terminals silently ignore the escape sequences — no fallback needed.
Design decisions
Each decision follows existing patterns in the codebase and/or established implementations in other terminal applications:
enableDetectedFeatures()/resetState()setFocusTracking) and bracketed paste (setBracketedPaste) are toggled — review feedback from #654setColorSchemeUpdates()helpersetBracketedPaste,setFocusTracking,setModifyOtherKeyspattern exactlyif (!self.state.color_scheme_updates)guardself.caps.bracketed_paste = trueincheckEnvironmentOverrides). Mode 2031 is safe to send unconditionally — unsupported terminals ignore it2031;1$yand2031;2$y1= mode set (active),2= mode recognizedfocus_tracking(1004),sync(2026), andbracketed_paste(2004) all match both response codes inprocessCapabilityResponse()CSI ? 996 nfocusHandler, before key handlercapabilityHandler,focusHandler)nullThemeModetype intypes.tsCursorStyle,WidthMethodUsage
Changes
packages/core/src/zig/terminal.zig—setColorSchemeUpdates()helper, enable inenableDetectedFeatures(), use inresetState(), broaden DECRPM detectionpackages/core/src/renderer.ts—_themeModeproperty,themeModeHandler,themeModegetterpackages/core/src/types.ts—ThemeModetype,theme_modeevent inRendererEventsReferences
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.