Bug: If line wraps, SGR reset does not clear attrs after content #3818

Closed
opened 2026-01-30 23:30:47 +00:00 by claunia · 2 comments
Owner

Originally created by @jazzdelightsme on GitHub (Sep 10, 2019).

Environment

Windows build number: Microsoft Windows [Version 10.0.18362.295]
Windows Terminal version (if applicable): latest master

This is a little tricky to describe--please bear with me.

I've given the example repro using pwsh, but I have also checked with plain C++ code, compiled and then run from cmd, and it's still a problem (so pwsh/PSReadLine are not interfering).

Steps to reproduce

  1. Create a string "s" with SGR sequences that sets foreground to red, and background color to white, and then at the end of the string an SGR reset (which should set fg and bg back to their defaults: gray on black).
  2. Write the string to the console, and observe that it works as expected. After the content, the rest of the line (to the window edge) is black.
  3. Now make the string longer by just adding content in the middle... long enough that it will wrap.
  4. Write the string to the console, and observe that it works differently. After the end of the content, the rest of the line (to the window edge) is white.

Expected behavior:

The behavior should be the same, whether or not the line wraps. And I think the current behavior in the non-wrapping case seems correct.

Actual behavior:

If the line wraps, the altered background color inexplicably shows up after the end of the content, to the end of the line.

Example repro:

$csi = "`e["
$fgRed = "${csi}91m"
$bgWhite = "${csi}107m"
$reset = "${csi}0m"

$s = "default ${fgRed}fg red ${bgWhite}bg white, no wrapping${reset} (courtesy reset)"

$s

$s2 = "default ${fgRed}fg red ${bgWhite}bg white, this content should be long enough to cause the line to be wrapped blah blah blah blah blah blah blah blah blah blah blah${reset} (courtesy reset)"

$s2

Picture:
image

And actually, it gets weirder: if I tweak the string's length such that the wrap occurs in the middle of the "courtesy reset" portion of the content... the bug does not repro.

Originally created by @jazzdelightsme on GitHub (Sep 10, 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: Microsoft Windows [Version 10.0.18362.295] Windows Terminal version (if applicable): latest master ``` This is a little tricky to describe--please bear with me. I've given the example repro using pwsh, but I have also checked with plain C++ code, compiled and then run from cmd, and it's still a problem (so pwsh/PSReadLine are not interfering). # Steps to reproduce 1. Create a string "s" with SGR sequences that sets foreground to red, and background color to white, and then at the end of the string an SGR reset (which should set fg and bg back to their defaults: gray on black). 2. Write the string to the console, and observe that it works as expected. After the content, the rest of the line (to the window edge) is black. 3. Now make the string longer by just adding content in the middle... long enough that it will wrap. 4. Write the string to the console, and observe that it works differently. After the end of the content, the rest of the line (to the window edge) is white. # Expected behavior: The behavior should be the same, whether or not the line wraps. And I think the current behavior in the non-wrapping case seems correct. # Actual behavior: If the line wraps, the altered background color inexplicably shows up after the end of the content, to the end of the line. # Example repro: ```powershell $csi = "`e[" $fgRed = "${csi}91m" $bgWhite = "${csi}107m" $reset = "${csi}0m" $s = "default ${fgRed}fg red ${bgWhite}bg white, no wrapping${reset} (courtesy reset)" $s $s2 = "default ${fgRed}fg red ${bgWhite}bg white, this content should be long enough to cause the line to be wrapped blah blah blah blah blah blah blah blah blah blah blah${reset} (courtesy reset)" $s2 ``` Picture: ![image](https://user-images.githubusercontent.com/771085/64643004-64d14d80-d3c4-11e9-97fa-c7c1953ebf25.png) And actually, it gets weirder: if I tweak the string's length such that the wrap occurs in the middle of the "courtesy reset" portion of the content... the bug does not repro.
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-30 23:30:47 +00:00
Author
Owner

@j4james commented on GitHub (Sep 10, 2019):

This is to be expected. When the content wraps at the bottom of the viewport it causes the buffer to scroll up, and the newly revealed line is filled with the current background color, which is white. If you cleared the screen before outputting the s2 you'd see the end of the line with a black background.

For comparison, here's a similar test case in an XTerm shell on Ubuntu. Notice that it's only the last occurrence (where the screen has scrolled) that has the white background at the end of the line.

image

@j4james commented on GitHub (Sep 10, 2019): This is to be expected. When the content wraps at the bottom of the viewport it causes the buffer to scroll up, and the newly revealed line is filled with the current background color, which is white. If you cleared the screen before outputting the _s2_ you'd see the end of the line with a black background. For comparison, here's a similar test case in an XTerm shell on Ubuntu. Notice that it's only the last occurrence (where the screen has scrolled) that has the white background at the end of the line. ![image](https://user-images.githubusercontent.com/4181424/64647012-1e094500-d410-11e9-8986-63aec63cb86e.png)
Author
Owner

@jazzdelightsme commented on GitHub (Sep 10, 2019):

Whoa! Yep, that seems to explain it. Thanks @j4james !

@jazzdelightsme commented on GitHub (Sep 10, 2019): Whoa! Yep, that seems to explain it. Thanks @j4james !
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#3818