Skip to content

Add terminal push detection via OSC 11 and mode 2031 - #2

Open
lederniermagicien wants to merge 2 commits into
ferologics:mainfrom
lederniermagicien:feat/terminal-native-detection
Open

Add terminal push detection via OSC 11 and mode 2031#2
lederniermagicien wants to merge 2 commits into
ferologics:mainfrom
lederniermagicien:feat/terminal-native-detection

Conversation

@lederniermagicien

Copy link
Copy Markdown

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 ?2031h so the terminal can push a CSI ?997;{1|2}n sequence 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 returns null on 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_DISABLE written on shutdown. 20 tests, all passing.

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.
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