Add terminal push detection via OSC 11 and mode 2031 - #2
Open
lederniermagicien wants to merge 2 commits into
Open
Add terminal push detection via OSC 11 and mode 2031#2lederniermagicien wants to merge 2 commits into
lederniermagicien wants to merge 2 commits into
Conversation
Previously the extension relied solely on OS API polling (defaults/gsettings/reg)
to detect appearance changes. This works but is reactive only on each poll cycle.
Two new detection mechanisms are added on top of the existing polling fallback:
- On session start an OSC 11 background-colour query is sent to get an immediate
reading by deriving dark/light from the terminal's background luminance.
- Mode 2031 is enabled so the terminal can push a CSI ?997;{1|2}n notification
whenever its theme changes. Once a push notification is confirmed the polling
loop is stopped entirely for that session, and restarted if it wasn't.
COLORFGBG is also checked at the start of each sync cycle as a zero-cost
heuristic before spawning any OS subprocess.
notifyInfoIfUI and isSupportedPlatform are removed — the former was a thin
wrapper with one call site (inlined), the latter gated the entire extension on
three platforms. The extension now runs on all platforms; OS API detection simply
returns null on unsupported ones, leaving terminal-based detection still active.
Tests cover all new paths: COLORFGBG dark/light/priority/fallthrough, mode 2031
dark/light with debounce, polling suppression after push confirmed, OSC 11
dark/light, and MODE_2031_DISABLE on shutdown. TestContext gains onTerminalInput
and simulateTerminalInput; sessionShutdown is now also captured by the runtime
helper. README updated to reflect the two-tier detection model.
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.
What
Adds two terminal-native detection mechanisms on top of the existing OS API polling fallback.
OSC 11 query — on session start, the extension queries the terminal's background colour and derives dark/light from its luminance. This gives an immediate reading without waiting for the first poll cycle.
Mode 2031 push notifications — the extension enables
?2031hso the terminal can push aCSI ?997;{1|2}nsequence whenever its theme changes. Once a push is confirmed, the polling loop is stopped for the session. This makes theme switching instant and eliminates unnecessary subprocess spawning.COLORFGBG — checked at the start of every sync cycle as a zero-cost heuristic before spawning any OS process.
Why
Polling works but is inherently laggy and always spawns a subprocess. Terminals that support mode 2031 can push changes instantly; OSC 11 removes the delay on startup. Both mechanisms degrade gracefully — if the terminal doesn't respond, the extension falls back to polling as before.
Other changes
isSupportedPlatform()removed — the guard prevented terminal-based detection from running on unsupported platforms even though it doesn't depend on the OS. The extension now starts everywhere;detectAppearance()simply returnsnullon unknown platforms.notifyInfoIfUI()restored — it was dropped in the staged changes but is still referenced in the command handler.Tests
All new paths are covered: COLORFGBG (dark, light, 3-segment, priority over OS, invalid fallthrough), mode 2031 (dark, light, debounce, polling suppression after push confirmed), OSC 11 (dark, light), and
MODE_2031_DISABLEwritten on shutdown. 20 tests, all passing.