Standardise the color table order #15491

Closed
opened 2026-01-31 04:40:07 +00:00 by claunia · 2 comments
Owner

Originally created by @j4james on GitHub (Oct 8, 2021).

Description of the new feature/enhancement

In our current implementation, we use two different orderings for the color tables. The WT color table use ANSI order (i.e. black, red, green, yellow, blue...), while the conhost color table using a Windows order (i.e. black, blue, green, cyan, red...).

This means that the WT and conhost dispatchers have to use a different set of constants when processing ANSI SGR sequences, and conhost needs to transpose and indexed-colors with Xterm256ToWindowsIndex. Then when it comes to the conpty implementation, the VtRenderer has to go through the same process in reverse, translating the indexed colors from Windows order back to ANSI order.

Ideally the two color tables should be using the same order, so the two dispatchers can use the exact same code, and we will eventually be able to merge the two code bases (i.e. #3849). And I'm hoping this change might also enable us to merge and simplify parts of the renderer that are now handled separately in WT and conhost.

Proposed technical implementation details (optional)

The idea is that the translation will now need to happen when processing legacy color attributes that have come from the console APIs, or when returning legacy color attributes in console API queries. There will also be parts of conhost that need translation when initializing the color tables with legacy config, like the registry.

But the active color tables themselves will always be in ANSI order, and the TextColor values in the buffer will always use ANSI order. All VT sequences, and queries will get to pass through indexed values exactly as they are, without the need for translation.

The only downside I can see is that there could be a performance hit in legacy APIs that read or write a large series of attribute values, but I'm hoping that will be negligible. I've got a WIP of this change, but I haven't had a chance to do any performance testing yet.

Originally created by @j4james on GitHub (Oct 8, 2021). # Description of the new feature/enhancement In our current implementation, we use two different orderings for the color tables. The WT color table use ANSI order (i.e. black, red, green, yellow, blue...), while the conhost color table using a Windows order (i.e. black, blue, green, cyan, red...). This means that the WT and conhost dispatchers have to use a different set of constants when processing ANSI SGR sequences, and conhost needs to transpose and indexed-colors with `Xterm256ToWindowsIndex`. Then when it comes to the conpty implementation, the `VtRenderer` has to go through the same process in reverse, translating the indexed colors from Windows order back to ANSI order. Ideally the two color tables should be using the same order, so the two dispatchers can use the exact same code, and we will eventually be able to merge the two code bases (i.e. #3849). And I'm hoping this change might also enable us to merge and simplify parts of the renderer that are now handled separately in WT and conhost. # Proposed technical implementation details (optional) The idea is that the translation will now need to happen when processing legacy color attributes that have come from the console APIs, or when returning legacy color attributes in console API queries. There will also be parts of conhost that need translation when initializing the color tables with legacy config, like the registry. But the active color tables themselves will always be in ANSI order, and the `TextColor` values in the buffer will always use ANSI order. All VT sequences, and queries will get to pass through indexed values exactly as they are, without the need for translation. The only downside I can see is that there could be a performance hit in legacy APIs that read or write a large series of attribute values, but I'm hoping that will be negligible. I've got a WIP of this change, but I haven't had a chance to do any performance testing yet.
Author
Owner

@zadjii-msft commented on GitHub (Oct 8, 2021):

I don't see why not. I have no doubt this is something you could do without breaking any sort of backwards compatibility ☺️

@zadjii-msft commented on GitHub (Oct 8, 2021): I don't see why not. I have no doubt this is something you could do without breaking any sort of backwards compatibility ☺️
Author
Owner

@ghost commented on GitHub (Feb 3, 2022):

:tada:This issue was addressed in #11602, which has now been successfully released as Windows Terminal Preview v1.13.10336.0.🎉

Handy links:

@ghost commented on GitHub (Feb 3, 2022): :tada:This issue was addressed in #11602, which has now been successfully released as `Windows Terminal Preview v1.13.10336.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.13.10336.0) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#15491