Underline not rendered after some SGR 22/39/49 #4289

Closed
opened 2026-01-30 23:43:04 +00:00 by claunia · 7 comments
Owner

Originally created by @egmontkob on GitHub (Oct 5, 2019).

Environment

Windows build number: Win32NT 10.0.18362.0
Windows Terminal version (if applicable): 0.5.2762.0

Steps to reproduce

echo -e '\e[4m underlined \e[33m yellow \e[39m should still be underlined \e[m'

Expected behavior

The entire line should be underlined.

Actual behavior

The "should still be underlined" bits aren't underlined.

Note that SGR codes 22, 27, 39 and 49 seem to cause this effect, but only if they're predeced by a 1, 7, 30-37 or 40-47, resp., that is, only if they do actually turn off some other attribute.

Also note that if the "should still be underlined" text is made longer so that it overflows to the next line (or even multiple new lines), it's underlined in the last one of these lines. This makes it perhaps a reincarnation of #47.

Furthermore, changing the window width and thus causing a reflow of the text removes the underlining from the last line.

Originally created by @egmontkob on GitHub (Oct 5, 2019). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 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 Windows build number: Win32NT 10.0.18362.0 Windows Terminal version (if applicable): 0.5.2762.0 ``` # Steps to reproduce echo -e '\e[4m underlined \e[33m yellow \e[39m should still be underlined \e[m' # Expected behavior The entire line should be underlined. # Actual behavior The "should still be underlined" bits aren't underlined. Note that SGR codes `22`, `27`, `39` and `49` seem to cause this effect, but only if they're predeced by a `1`, `7`, `30-37` or `40-47`, resp., that is, only if they do actually turn off some other attribute. Also note that if the "should still be underlined" text is made longer so that it overflows to the next line (or even multiple new lines), it's underlined in the last one of these lines. This makes it perhaps a reincarnation of #47. Furthermore, changing the window width and thus causing a reflow of the text removes the underlining from the last line.
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 6, 2019):

Investigation yields that the attributes are read & stored correctly; next step is looking at VtEngine (ConPTY out).

@DHowett-MSFT commented on GitHub (Oct 6, 2019): Investigation yields that the attributes are read & stored correctly; next step is looking at VtEngine (ConPTY out).
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 6, 2019):

VtEngine::_RgbUpdateDrawingBrushes doesn't factor in any attributes other than bold & color (actual RGB value) when it decides to emit \e[m. This is something that'll probably be addressed by #2661, which suggests that we should defer converting attributes into RGB values (and other unpacked flags) as late as possible.

@DHowett-MSFT commented on GitHub (Oct 6, 2019): `VtEngine::_RgbUpdateDrawingBrushes` doesn't factor in any attributes other than bold & color (actual RGB value) when it decides to emit `\e[m`. This is something that'll probably be addressed by #2661, which suggests that we should defer converting attributes into RGB values (and other unpacked flags) as late as possible.
Author
Owner

@DHowett-MSFT commented on GitHub (Oct 6, 2019):

I'm keeping this one open as a linked workitem. Thanks for finding this, @egmontkob!

@DHowett-MSFT commented on GitHub (Oct 6, 2019): I'm keeping this one open as a linked workitem. Thanks for finding this, @egmontkob!
Author
Owner

@aeiplatform commented on GitHub (Oct 6, 2019):

Since echo -e is not POSIX compliant, you should rather combine printf and tput for text formatting.
In POSIX echo acts like echo -e by default but not in bash, because of arguments expansion.

I guess this command for my current bash works as expected.
(GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)).
image

In POSIX this would be equivalent for yours example:
printf "%s underline %s yellow %s should still be underlined %s\n" "$(tput smul)" "$(tput setaf 3)" "$(tput setaf 7)" "$(tput sgr0)"

@aeiplatform commented on GitHub (Oct 6, 2019): Since `echo -e` is not POSIX compliant, you should rather combine `printf` and `tput` for text formatting. In POSIX `echo` acts like `echo -e` by default but not in bash, because of arguments expansion. I guess this command for my current bash works as expected. (GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)). ![image](https://user-images.githubusercontent.com/56209373/66266814-52fb9280-e82a-11e9-9556-5a07107cbff8.png) In POSIX this would be equivalent for yours example: `printf "%s underline %s yellow %s should still be underlined %s\n" "$(tput smul)" "$(tput setaf 3)" "$(tput setaf 7)" "$(tput sgr0)"`
Author
Owner

@egmontkob commented on GitHub (Oct 6, 2019):

Re echo -e vs. printf: I know, using echo -e is a bad habit of mine, I know I should use printf. :)

I disagree with tput, though (and echo vs printf doesn't really matter either). I'm not writing portable software here, I'm writing a reproducer test case for a bug in the terminal emulator.

Using tput instead of raw escape sequence introduces a level of indirection, makes the behavior depend on $TERM as well as potentially the terminfo version where my intent is not to, and is IMO harder to read. The terminal emulator cares about numbers like 37 or 39, and not terminfo capabilities such as setaf.

Also, by far not all escape sequences can be generated by tput, let alone deliberately broken ones, which some of my other bugreports are about.

E.g. there's no terminfo capability I'm aware of that would generate \e[39m that my example uses. You mistakenly changed that to \e[37m, or, well, its tput equivalent, modifying the test case, which could be the reason for you not hitting the bug.

@egmontkob commented on GitHub (Oct 6, 2019): Re `echo -e` vs. `printf`: I know, using `echo -e` is a bad habit of mine, I know I should use `printf`. :) I disagree with `tput`, though (and `echo` vs `printf` doesn't really matter either). I'm not writing portable software here, I'm writing a reproducer test case for a bug in the terminal emulator. Using `tput` instead of raw escape sequence introduces a level of indirection, makes the behavior depend on `$TERM` as well as potentially the terminfo version where my intent is not to, and is IMO harder to read. The terminal emulator cares about numbers like 37 or 39, and not terminfo capabilities such as `setaf`. Also, by far not all escape sequences can be generated by `tput`, let alone deliberately broken ones, which some of my other bugreports are about. E.g. there's no terminfo capability I'm aware of that would generate `\e[39m` that my example uses. You mistakenly changed that to `\e[37m`, or, well, its `tput` equivalent, modifying the test case, which could be the reason for you not hitting the bug.
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 21, 2020):

Lol- I just hit this myself, forgot we had a bug on it and re-investigated it.

Apparently what I said months ago is still true. Weird how that works.

@DHowett-MSFT commented on GitHub (Feb 21, 2020): Lol- I just hit this myself, forgot we had a bug on it and re-investigated it. Apparently what I said months ago is still true. Weird how that works.
Author
Owner

@ghost commented on GitHub (Jul 22, 2020):

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

Handy links:

@ghost commented on GitHub (Jul 22, 2020): :tada:This issue was addressed in #6506, which has now been successfully released as `Windows Terminal Preview v1.2.2022.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.2.2022.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#4289