Combined SGR attributes 1 and 7, "Bold or increased intensity" and "Reverse video" do not render as expected #8981

Closed
opened 2026-01-31 01:42:55 +00:00 by claunia · 6 comments
Owner

Originally created by @rbeesley on GitHub (Jun 12, 2020).

Environment

Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.19640.0 Microsoft Windows NT 10.0.19640.0
Windows Terminal Preview
Version: 1.1.1611.0

Steps to reproduce

See the attached full capture for more guidance in what the R1C1 reference addresses are indicating.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /F "tokens=4 delims= " %%_ IN ('chcp') DO (SET CHCP=%%_)
IF DEFINED CHCP (
  chcp 65001>NUL
)

ECHO.
ECHO Baseline Foreground and Background:
ECHO.
ECHO ␛[33m           → Hello, World^^! :  R8C1
ECHO ␛[1;33m         → Hello, World^^! :  R9C1
ECHO ␛[30;43m        → Hello, World^^! :  R2C8
ECHO ␛[30;103m       → Hello, World^^! :  R2C9
ECHO.
ECHO.
ECHO Test Cases:
ECHO.
ECHO ␛[33m␛[43m      → Hello, World^^! :  R8C8
ECHO ␛[7;33m␛[43m    → Hello, World^^! : R40C8
ECHO.
ECHO ␛[33m␛[103m     → Hello, World^^! :  R8C9
ECHO ␛[7;33m␛[103m   → Hello, World^^! : R40C9
ECHO ␛[33;7m␛[103m   → Hello, World^^! :     -
ECHO ␛[103m␛[7;33m   → Hello, World^^! :     -
ECHO ␛[103m␛[33;7m   → Hello, World^^! :     -
ECHO.
ECHO ␛[1;33m␛[43m    → Hello, World^^! :  R9C8
ECHO ␛[1;7;33m␛[43m  → Hello, World^^! : R41C8
ECHO ␛[7;1;33m␛[43m  → Hello, World^^! :     -
ECHO ␛[43m␛[1;7;33m  → Hello, World^^! :     -
ECHO ␛[43m␛[7;1;33m  → Hello, World^^! :     -
ECHO.
ECHO ␛[1;33m␛[103m   → Hello, World^^! :  R9C9
ECHO ␛[1;7;33m␛[103m → Hello, World^^! : R41C9

IF DEFINED CHCP (
  chcp !CHCP!>NUL
)

ENDLOCAL

Expected behavior

With the string ␛[1;7;33m␛[43m R41C8␛[m, I believe that the foreground and background color output should be the same as ␛[33m␛[103m R8C9␛[m.

image

In this example, if ␛[33m␛[103m with a video reverse attribute ␛[7;33m␛[103m will invert like it is ␛[1;33m␛[43m, then the same should be true in the reverse. ␛[1;33m␛[43m with the video reverse attribute ␛[1;7;33m␛[43m should invert like it is ␛[33m␛[103m.

Actual behavior

Instead of switching the foreground and background colors, it looks like the intensity attribute is applied after switching the two colors.

image

This has the impact that you cannot see the dark text against the light background because the intensity attribute is applied after the background color is assigned the foreground color, and so when these are in the same color pairing it becomes light on light.

I chose this specific example because under Campbell there is enough contrast between the normal and the intensity colors to clearly demonstrate this problem, but as you can see in the full table the problem exists for all color pairings. You can also see that the reverse colors in a column, the foreground color maintains the same intensity for the entire set of rows, but it would be expected that they would alternate from light to dark between adjoining rows.

The additional test cases which don't have a reference in the table demonstrate that where in the order of attributes that the reverse video attribute is placed should not change the result. This is potentially an ambiguous case in the spec as it could be inferred that setting intensity before or after setting reverse video might have an impact, but I think it is more expressive and likely more how it was intended, that the reverse video attribute can be placed anywhere and reverses the foreground and background colors. An alternate consideration would be that it would actually invert the colors, not just flip the foreground for the background. The ECMA-048 standard actually defines it as "negative image" rather than invert, which is suggestive that flipping the foreground and background colors is the incorrect rendering anyway.

image

Originally created by @rbeesley on GitHub (Jun 12, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Platform ServicePack Version VersionString -------- ----------- ------- ------------- Win32NT 10.0.19640.0 Microsoft Windows NT 10.0.19640.0 ``` ```none Windows Terminal Preview Version: 1.1.1611.0 ``` # Steps to reproduce <!-- A description of how to trigger this bug. --> See the attached full capture for more guidance in what the R1C1 reference addresses are indicating. ```batch @ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION FOR /F "tokens=4 delims= " %%_ IN ('chcp') DO (SET CHCP=%%_) IF DEFINED CHCP ( chcp 65001>NUL ) ECHO. ECHO Baseline Foreground and Background: ECHO. ECHO ␛[33m → Hello, World^^! : R8C1 ECHO ␛[1;33m → Hello, World^^! : R9C1 ECHO ␛[30;43m → Hello, World^^! : R2C8 ECHO ␛[30;103m → Hello, World^^! : R2C9 ECHO. ECHO. ECHO Test Cases: ECHO. ECHO ␛[33m␛[43m → Hello, World^^! : R8C8 ECHO ␛[7;33m␛[43m → Hello, World^^! : R40C8 ECHO. ECHO ␛[33m␛[103m → Hello, World^^! : R8C9 ECHO ␛[7;33m␛[103m → Hello, World^^! : R40C9 ECHO ␛[33;7m␛[103m → Hello, World^^! : - ECHO ␛[103m␛[7;33m → Hello, World^^! : - ECHO ␛[103m␛[33;7m → Hello, World^^! : - ECHO. ECHO ␛[1;33m␛[43m → Hello, World^^! : R9C8 ECHO ␛[1;7;33m␛[43m → Hello, World^^! : R41C8 ECHO ␛[7;1;33m␛[43m → Hello, World^^! : - ECHO ␛[43m␛[1;7;33m → Hello, World^^! : - ECHO ␛[43m␛[7;1;33m → Hello, World^^! : - ECHO. ECHO ␛[1;33m␛[103m → Hello, World^^! : R9C9 ECHO ␛[1;7;33m␛[103m → Hello, World^^! : R41C9 IF DEFINED CHCP ( chcp !CHCP!>NUL ) ENDLOCAL ``` # Expected behavior <!-- A description of what you're expecting, possibly containing screenshots or reference material. --> With the string `␛[1;7;33m␛[43m R41C8␛[m`, I believe that the foreground and background color output should be the same as `␛[33m␛[103m R8C9␛[m`. ![image](https://user-images.githubusercontent.com/3703112/84462524-23f0b880-ac24-11ea-8b04-efa3dce94b77.png) In this example, if `␛[33m␛[103m` with a video reverse attribute `␛[7;33m␛[103m` will invert like it is `␛[1;33m␛[43m`, then the same should be true in the reverse. `␛[1;33m␛[43m` with the video reverse attribute `␛[1;7;33m␛[43m` should invert like it is `␛[33m␛[103m`. # Actual behavior <!-- What's actually happening? --> Instead of switching the foreground and background colors, it looks like the intensity attribute is applied after switching the two colors. ![image](https://user-images.githubusercontent.com/3703112/84462257-64036b80-ac23-11ea-9a3e-a072798b9d08.png) This has the impact that you cannot see the dark text against the light background because the intensity attribute is applied after the background color is assigned the foreground color, and so when these are in the same color pairing it becomes light on light. I chose this specific example because under Campbell there is enough contrast between the normal and the intensity colors to clearly demonstrate this problem, but as you can see in the full table the problem exists for all color pairings. You can also see that the reverse colors in a column, the foreground color maintains the same intensity for the entire set of rows, but it would be expected that they would alternate from light to dark between adjoining rows. The additional test cases which don't have a reference in the table demonstrate that where in the order of attributes that the reverse video attribute is placed should not change the result. This is potentially an ambiguous case in the spec as it could be inferred that setting intensity before or after setting reverse video might have an impact, but I think it is more expressive and likely more how it was intended, that the reverse video attribute can be placed anywhere and reverses the foreground and background colors. An alternate consideration would be that it would actually invert the colors, not just flip the foreground for the background. The [ECMA-048 standard](https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf) actually defines it as "negative image" rather than invert, which is suggestive that flipping the foreground and background colors is the incorrect rendering anyway. ![image](https://user-images.githubusercontent.com/3703112/84455560-775a0b00-ac12-11ea-9ce3-92e59ba929cf.png)
claunia added the Area-RenderingIssue-BugResolution-DuplicateProduct-Conpty labels 2026-01-31 01:42:55 +00:00
Author
Owner

@rbeesley commented on GitHub (Jun 12, 2020):

I explored this a little more and using SGR 1 to set the foreground intensity gives different results than using 90-97. This may be more of a problem with regard to not supporting bold. I'll provide more details when I can capture them and add them to this issue.

@rbeesley commented on GitHub (Jun 12, 2020): I explored this a little more and using SGR 1 to set the foreground intensity gives different results than using 90-97. This may be more of a problem with regard to not supporting bold. I'll provide more details when I can capture them and add them to this issue.
Author
Owner

@j4james commented on GitHub (Jun 13, 2020):

Your original test case sounds like #3076, which is essentially a variant of the #2661 issue. I know it's fixed in my 2661 branch.

In general, if it works in conhost, but fails in Windows Terminal, then it's likely some variant of #2661.

@j4james commented on GitHub (Jun 13, 2020): Your original test case sounds like #3076, which is essentially a variant of the #2661 issue. I know it's fixed in my 2661 branch. In general, if it works in conhost, but fails in Windows Terminal, then it's likely some variant of #2661.
Author
Owner

@rbeesley commented on GitHub (Jun 13, 2020):

@j4james, spot on. It works in conhost but fails in Windows Terminal.

@rbeesley commented on GitHub (Jun 13, 2020): @j4james, spot on. It works in conhost but fails in Windows Terminal.
Author
Owner

@zadjii-msft commented on GitHub (Jun 15, 2020):

For my own sanity:

expected actual
@zadjii-msft commented on GitHub (Jun 15, 2020): For my own sanity: expected | actual -- | -- ![](https://user-images.githubusercontent.com/3703112/84462524-23f0b880-ac24-11ea-8b04-efa3dce94b77.png) | ![](https://user-images.githubusercontent.com/3703112/84462257-64036b80-ac23-11ea-9a3e-a072798b9d08.png)
Author
Owner

@DHowett commented on GitHub (Jun 16, 2020):

Thanks for the first-line triage, and the excellent repros @rbeesley. I'm gonna call this one a /dupe of #2661 #3076 (even though the graphic rendition is different, they're all gated on this one thing.)

#6506 fixes this, as well. Please ignore the garish coloring -- it is intended to catch issues related to applications emitting legacy attributes.

image

@DHowett commented on GitHub (Jun 16, 2020): Thanks for the first-line triage, and the excellent repros @rbeesley. I'm gonna call this one a /dupe of #2661 #3076 (even though the graphic rendition is different, they're all gated on this one thing.) #6506 fixes this, as well. Please ignore the garish coloring -- it is intended to catch issues related to applications emitting legacy attributes. ![image](https://user-images.githubusercontent.com/189190/84718184-e003f900-af2c-11ea-80b3-1a639c481588.png)
Author
Owner

@ghost commented on GitHub (Jun 16, 2020):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Jun 16, 2020): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8981