feat(parser): respond to OSC 10/11 fg/bg color queries#57
Open
roramirez wants to merge 1 commit into
Open
Conversation
Report the active theme's default fg (OSC 10) and bg (OSC 11) in the xterm rgb:RRRR/GGGG/BBBB format when a program queries with `?`. This lets TUIs such as Neovim (`background=auto`) auto-detect a dark or light theme. Color *set* requests are ignored so the PTY cannot change the theme.
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 it does
mmterm now responds to OSC 10 (foreground color) and OSC 11 (background color) when a program queries them with
?. The response uses the xtermrgb:RRRR/GGGG/BBBBformat with the active theme color.This unblocks light/dark theme auto-detection in TUIs such as Neovim/Vim (
:set background=auto), which query the terminal's background color to pick a colorscheme.Color set requests (e.g.
OSC 10;#ff0000) are ignored on purpose: the PTY must not be able to change the theme.Changes
src/terminal/parser.rs: new free functionosc_color_query, called fromosc_dispatch. Reusesgrid.pending_responses(same channel as DSR/DA) andgrid.default_fg/grid.default_bg.src/terminal/parser_test.rs: 3 tests (fg, bg, and that a set is ignored).CHANGELOG.md.How to test manually
cargo run.]11;rgb:1e1e/1e1e/2e2e), without hanging the prompt.printf '\e]10;?\e\\'; echo.nvimand, with a colorscheme that auto-detects the background, confirm it picks the right variant (or:set background=auto). The result should match the real background (light/dark).rgbchanges to match the new theme.printf '\e]10;#ff0000\e\\'changes no colors and sends no response.Tests
cargo test— full suite green (includesosc10_query_reports_foreground,osc11_query_reports_background,osc_color_set_is_ignored).