Skip to content

Rough draft of DECRQSS implementation.#1

Merged
lihop merged 3 commits into
lihop:masterfrom
diggernet:DECRQSS
Aug 11, 2025
Merged

Rough draft of DECRQSS implementation.#1
lihop merged 3 commits into
lihop:masterfrom
diggernet:DECRQSS

Conversation

@diggernet
Copy link
Copy Markdown

My C is pretty rusty, so I'm pretty sure that dcs_decrqss() is much clumsier than it should be. But you ought to be able to see what I'm going for. Improvements are welcome.
One obvious concern is that this won't work with RGB colors, because SGR wasn't designed for that.
Also, while I assume that fccode and bccode contain the SGR color numbers, I'm not 100% sure of that, and I don't know what range of values libtsm currently supports. This current code assumes they'll be 0-99, but the specs at invisible-island.net suggest that values over 100 are possible depending on implementation.

@lihop
Copy link
Copy Markdown
Owner

lihop commented Feb 6, 2024

Thanks for this. It looks pretty good at a glance. I will give it a proper look and test eventually.

lihop added 2 commits August 10, 2025 12:31
Adds orig_fgr and orig_sgr attributes for storing the original SGR color
numbers that libtsm was correctly interpreting but not storing.

Updates DECRQSS to report these correct numbers rather than libtsm's
internal palette color numbers that fccode and bccode are set to.
@lihop
Copy link
Copy Markdown
Owner

lihop commented Aug 11, 2025

Hi @diggernet,

I recently updated this libtsm fork and finally got around to reviewing this. I've resolved some merge conflicts and made some small adjustments.

One obvious concern is that this won't work with RGB colors, because SGR wasn't designed for that.

Right. When RGB colors are used fccode/bccode are -1 so the function will correctly skip them.

Also, while I assume that fccode and bccode contain the SGR color numbers, I'm not 100% sure of that

Your concern was correct! It turns out that fccode and bccode, while set correctly from the SGR color number, were not being set to the SGR color number but instead libtsm's own internal color palette number. For example:

libtsm/src/tsm/tsm-vte.c

Lines 1387 to 1389 in c477e0c

case 107:
vte->cattr.bccode = TSM_COLOR_WHITE;
break;

This meant that setting the color to bright white (terminal.write("\u001b[107mTEST")) would incorrectly report back 15 rather than 107.

In order to fix this, I've added two new attributes orig_fgr and orig_bgr which store the actual SGR color numbers that we can report back.

I don't know what range of values libtsm currently supports. This current code assumes they'll be 0-99, but the specs at invisible-island.net suggest that values over 100 are possible depending on implementation.

libtsm supports SGR codes 30-127 for basic colors, plus full 256-color palette (0-255) and true color RGB, so I've update the range to < 256 to support this.

The rest of the PR is great. I look forwards to adding these changes to the first GodotXterm Godot 4 asset library release which is almost ready to go!

@lihop lihop merged commit ca09537 into lihop:master Aug 11, 2025
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.

2 participants