Skip to content

feat(parser): respond to OSC 10/11 fg/bg color queries#57

Open
roramirez wants to merge 1 commit into
mainfrom
feature/osc-10-11-color-query
Open

feat(parser): respond to OSC 10/11 fg/bg color queries#57
roramirez wants to merge 1 commit into
mainfrom
feature/osc-10-11-color-query

Conversation

@roramirez

@roramirez roramirez commented Jul 4, 2026

Copy link
Copy Markdown
Owner

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 xterm rgb:RRRR/GGGG/BBBB format 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 function osc_color_query, called from osc_dispatch. Reuses grid.pending_responses (same channel as DSR/DA) and grid.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

  1. In this worktree: cargo run.
  2. In the mmterm terminal, run the background query:
    printf '\e]11;?\e\\'; echo
    It should print the response with the theme's background color (e.g. ]11;rgb:1e1e/1e1e/2e2e), without hanging the prompt.
  3. Repeat for the foreground: printf '\e]10;?\e\\'; echo.
  4. With Neovim installed: open nvim and, 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).
  5. Change the mmterm theme and repeat step 2: the reported rgb changes to match the new theme.
  6. Regression: a set must not change anything → printf '\e]10;#ff0000\e\\' changes no colors and sends no response.

Tests

cargo test — full suite green (includes osc10_query_reports_foreground, osc11_query_reports_background, osc_color_set_is_ignored).

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