[PR #17729] Add support for querying Xterm dynamic colors and palette #31341

Open
opened 2026-01-31 09:46:40 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/17729

State: closed
Merged: Yes


This pull request adds support for querying all of the "dynamic
resource" colors (foreground, background, cursor) as well as the entire
color palette using OSC 4, 10, 11 and 12 with the ? color specifier.

To ease integration and to make it easier to extend later, I have
consolidated SetDefaultForeground, SetDefaultBackground and
SetCursorColor into one function SetXtermColorResource, plus its
analog RequestXtermColorResource.

Those functions will map xterm resource OSC numbers to color table
entries and optionally color alias entries using a constant table. The
alias mappings are required to support reassigning the default
foreground and background to their indexed entries after a DECAC.

While there are only three real entries in the mapping table right now,
I have designs on bringing in selection background (xterm "highlight")
and foreground (xterm "highlightText").

We can also extend this to support resetting via OSC 110-119. However,
at the adapter layer we do not have the requisite information to restore
any of the colors (even the cursor color!) to the user's defaults.

OSC 10 and OSC 11 queries report the final values of
DECAC-reassigned entries, under the assumption that an application
asking for them wants to make a determination regardless of their
internal meaning to us (that is: they read through the aliased color to
its final destination in the color palette.)

I've tested this with lsix, which detects the background color before
generating sixel previews. It works great!

ConPTY does not currently pass OSC sequences received on the input
handle, so work was required to make it do so.

Closes #3718

**Original Pull Request:** https://github.com/microsoft/terminal/pull/17729 **State:** closed **Merged:** Yes --- This pull request adds support for querying all of the "dynamic resource" colors (foreground, background, cursor) as well as the entire color palette using OSC 4, 10, 11 and 12 with the `?` color specifier. To ease integration and to make it easier to extend later, I have consolidated `SetDefaultForeground`, `SetDefaultBackground` and `SetCursorColor` into one function `SetXtermColorResource`, plus its analog `RequestXtermColorResource`. Those functions will map xterm resource OSC numbers to color table entries and optionally color _alias_ entries using a constant table. The alias mappings are required to support reassigning the default foreground and background to their indexed entries after a `DECAC`. While there are only three real entries in the mapping table right now, I have designs on bringing in selection background (xterm "highlight") and foreground (xterm "highlightText"). We can also extend this to support resetting via OSC 110-119. However, at the adapter layer we do not have the requisite information to restore any of the colors (even the cursor color!) to the user's defaults. `OSC 10` and `OSC 11` queries report the final values of `DECAC`-reassigned entries, under the assumption that an application asking for them wants to make a determination regardless of their internal meaning to us (that is: they read through the aliased color to its final destination in the color palette.) I've tested this with lsix, which detects the background color before generating sixel previews. It works great! ConPTY does not currently pass OSC sequences received on the input handle, so work was required to make it do so. Closes #3718
claunia added the pull-request label 2026-01-31 09:46:40 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31341