Skip to content

Conversation

@malsyned
Copy link
Contributor

@malsyned malsyned commented Nov 7, 2025

  • Add do_osc_internal() for handling certain OSC commands within libtsm instead of delegating them to vte->osc_cb().
  • Respond to OSC 10 (fg color) and OSC 11 (bg color) queries

Fix #53

@kdj0c
Copy link
Collaborator

kdj0c commented Nov 7, 2025

Thanks for your contribution.
That's really good, I don't have much comments, you even added some unit tests.
I will merge it next Monday to give a chance to other to review.

Do you have an application that uses this, to check that it works?

@malsyned
Copy link
Contributor Author

malsyned commented Nov 7, 2025

Do you have an application that uses this, to check that it works?

Yup! I have a Python + curses TUI 3-way merge tool I'm developing that uses this functionality to pick a suitable selection highlight color. Here's a before and after running it in GtkStm:

Before

tuimerge fails to read the background color with OSC 11, so doesn't try to add a background highlight and just highlights the gutter indicator.

image

After

tuimerge succeeds at querying the background color, so computes a subtle highlight color from it.

image

And a quick hack to color_palette_legacy to show it reacting to the different background color. (It looks better in terminals that allow assigning colors to palette entries, but it's doing its best with the 216-color indexed color palette).

image

Other examples

Here is that same code, adapting to the background color of Ghostty and modifying the palette entry for a closer match, to show that the code that works after this PR also works on other terminals:

image image

@malsyned
Copy link
Contributor Author

malsyned commented Nov 7, 2025

And why not, a GtkTsm example where it detects a light-mode theme and uses a darker highlight instead of a lighter one.

image

Add do_osc_internal() for handling certain OSC commands within libtsm
instead of delegating them to osc_cb.

Fix Aetf#53
@malsyned
Copy link
Contributor Author

malsyned commented Nov 8, 2025

Just pushed a few small style cleanups. Works exactly the same, tests still pass.

@malsyned
Copy link
Contributor Author

malsyned commented Nov 8, 2025

I was just looking over the source for msedit and found that it uses OSC 4 as well to query the colors of the 16 SGR colors. I'm going to add support for that as well to this PR just to round out the capabilities.

This is in preparation for OSC 4 ? query support.
@malsyned malsyned changed the title Respond to OSC 10 (fg color) and OSC 11 (bg color) queries Respond to OSC 10 (fg color) and OSC 11 (bg color) and OSC 4 (256-color) queries Nov 8, 2025
@malsyned
Copy link
Contributor Author

malsyned commented Nov 8, 2025

Just pushed a couple of commits that add support for OSC 4 queries. Here's GtkTsm and various other terminals responding to these queries, to show that they respond in the same way:

GtkTsm

image

XTerm

image

Ghostty

image

VTE (gnome-terminal)

image

@malsyned
Copy link
Contributor Author

malsyned commented Nov 8, 2025

Adding OSC 4 ? support seems to give msedit whatever it's looking for to enable it to match its theme to the terminal's palette. Here's a before-and-after with the legacy TSM_COLOR_BACKGROUND set to [60, 20, 30]:

libtsm/main

image

malsyned/issue-53-osc-query

image

@malsyned malsyned changed the title Respond to OSC 10 (fg color) and OSC 11 (bg color) and OSC 4 (256-color) queries Respond to OSC 10 (fg color), OSC 11 (bg color) and OSC 4 (256-color) queries Nov 8, 2025
@malsyned
Copy link
Contributor Author

malsyned commented Nov 8, 2025

Woke up this morning and realized I didn't love the structure of my OSC4 parser, so I made some tweaks. I'm done with this for now, pending change requests.

@kdj0c kdj0c merged commit 2e0df00 into Aetf:main Nov 10, 2025
2 checks passed
@malsyned malsyned deleted the issue-53-osc-query branch November 10, 2025 15:09
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.

Feature request: respond to foreground and background color queries OSC 10;? and OSC 11;?

2 participants