Skip to content

terminal: answer OSC default color queries#1394

Open
amir-jakoby wants to merge 2 commits into
mobile-shell:masterfrom
amir-jakoby:fix/osc-default-color-queries
Open

terminal: answer OSC default color queries#1394
amir-jakoby wants to merge 2 commits into
mobile-shell:masterfrom
amir-jakoby:fix/osc-default-color-queries

Conversation

@amir-jakoby

@amir-jakoby amir-jakoby commented Jun 17, 2026

Copy link
Copy Markdown

terminal: Answer OSC default color queries

Fixes #1145.
Fixes #1351.
Related to #1350, but this PR intentionally does not implement OSC 4 indexed color queries.

Adds support for OSC 10/11 default foreground/background color queries through mosh. The wrapper probes the local terminal for default colors, forwards only sanitized rgb values to mosh-server, and the server terminal emulator answers remote application queries from those values.

Description:

  • Probe the local controlling terminal for OSC 10/11 replies with a short timeout.
  • Forward sanitized default foreground/background colors as MOSH_DEFAULT_FG and MOSH_DEFAULT_BG.
  • Answer OSC 10/11 ? queries in the server emulator only when configured values are valid.
  • Add a regression test for replies, missing values, and invalid values.

Validation:

  • perl -Mdiagnostics -c scripts/mosh.pl
  • make -C src/tests check TESTS=terminal-osc-default-colors
  • PTY wrapper simulation confirmed parsed OSC replies are forwarded into the remote server command.
  • make -j4 check passed the new regression but local window-resize.test errored in this macOS/tmux environment; the log showed the driver sent qexit to the shell instead of exiting less.

@achernya

Copy link
Copy Markdown
Collaborator

I am not a fan of the approach using environment variables to pass this around. I am concerned about forwards and backwards compatibility.

@amir-jakoby

amir-jakoby commented Jun 21, 2026

Copy link
Copy Markdown
Author

@achernya I reworked this to avoid using environment variables for the wrapper/server handoff.

The revised version sends the probed default colors as internal mosh-server new -@ mosh-default-fg=... -@ mosh-default-bg=... arguments instead of MOSH_DEFAULT_FG/BG. New servers consume those -@ payloads and thread the values into the terminal object; old servers already understand -@ ARG as an argument-eating compatibility option, so they consume the pair quietly and continue without enabling the feature.

I think this is better than the env-var approach because:

  • no new values leak into the user's remote shell environment or child processes;
  • MOSH_DEFAULT_FG/BG do not become an accidental public ABI;
  • there is no new documented/public mosh-server option surface;
  • there is no protocol/protobuf change, and old-client/new-server or new-client/old-server both degrade to no OSC default-color replies;
  • the terminal emulator no longer reads getenv() at query time, so the behavior is carried as server startup state instead of ambient process state.

I also kept the scope limited to OSC 10/11 default foreground/background replies and added a small regression for valid 1-4 digit XParseColor components.

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.

Add support for OSC 10 (get foreground color) Mosh does not handle OSC 11 background color requests

2 participants