Apps can tell whether the terminal is light or dark, and hear when it flips
Explore this workspace.
Technical background
A program that follows the terminal's light or dark appearance, such as shefrd's "follow the terminal" theme or Neovim's background, asks the terminal which it is. On Windows the console layer every local and WSL tab runs through never passes the usual question (the background colour) on, and the other one went unanswered, so such a program always assumed dark. Torbie now answers that question and, to a program that asked to be told, sends the new answer the moment the colour scheme changes, including when it follows the Windows theme. Nothing is sent to a program that did not ask.
The problem
A program can learn the terminal's appearance two ways: ask for the background colour (OSC 11 ; ?), or ask light-or-dark directly (CSI ? 996 n) and set mode 2031 to be told when it changes. xterm.js answers the first, but the inbox ConPTY that every local and WSL tab runs through never forwards that query to it. ConPTY does forward the second, which xterm.js 6.0 did not implement. So shefrd's "follow the terminal" theme drew its dark half in a light window.
How it works
Torbie answers CSI ? 996 n with CSI ? 997 ; 1 n (dark) or ; 2 n (light), tracks mode 2031, answers whether it is set, and sends the report unasked when the pane's colours change while it is. Light or dark is read off the colour the pane is drawn on, the same colour OSC 11 reports.
A probe in WSL, through the inbox ConPTY, light scheme then flipped to dark
before after OSC 11 ; ? (nothing) (nothing) CSI ? 996 n (nothing) ESC[?997;2n flip to dark, 2031 set (nothing) ESC[?997;1n
Details
- Verified with shefrd in a WSL tab of a hidden build: it drew catppuccin-latte in a light window, switched to catppuccin when the scheme flipped to dark, and back.
- A flip that follows the Windows theme (colour scheme mode Auto) is reported too.
What this does not claim
OSC 11 ; ?still does not arrive through the inbox ConPTY; switching to node-pty's bundled conpty would deliver it, and is not done here.- A transparent terminal background (vibrancy) is judged by the colour scheme's own background, not by what shows through.