question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Background color leaking to next scrolled line

See original GitHub issue

Steps to reproduce

Issue this command on the last line of your window so that scrolling is taking place:

Write-Host "Bebop" -BackgroundColor Green -ForegroundColor Black

Expected behavior

The line below the “Bebop” line is clean (i.e. what was done with Write-Host doesn’t leak into the following line)

Actual behavior

The line is painted green image

Environment data

PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Fred-Vatincommented, Jun 7, 2021

Similar issues or duplicates

#14686 #11267

Setup

I can reproduce.

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Tested with cleaned session from user installed modules and without PSReadline.

PS>gmo | select name, version

Name                            Version
----                            -------
Microsoft.PowerShell.Management 7.0.0.0
Microsoft.PowerShell.Utility    7.0.0.0

Step to reproduce

I you run this below code directly or via a file.ps1, the result is the same.

[Enum]::GetValues([ConsoleColor]) |
ForEach-Object {
   $color = $_.ToString().Trim()
   if (($color -like 'dark*') -or ($color -like 'black')) {
   	Write-Host 'test' -BackgroundColor Black
   	Write-Host "$color" -ForegroundColor $color
   	Write-Host "$color" -ForegroundColor White -BackgroundColor $color
   } else {
   	Write-Host 'test' -BackgroundColor Black
   	Write-Host "$color" -ForegroundColor $color
   	Write-Host "$color" -ForegroundColor Black -BackgroundColor $color
   }
}

Results

Rendering in console or in WT. Look at the bottom of the window. I suspect the scroll cause the issue as mentioned in one of the issue mentioned before. test

As we can see, write-host with -BackgroundColor option fills the entire line with the color. For some reason, the line length seems to be longer than the console width and leak to the the next scroll line. This is solved when resizing console width.

Here is running command colortool -c Gif Animate 2021-06-07 09h49 #335 _optimized

Expectation

First, documentation doesn’t mention write-host with -BackgroundColor is supposed to fill the entire line instead of the object alone. This needs to be clarified.

Secondly, it seems that line length seen by write-host is longer than the console width. In any case, background color should not line break.

Workaround (almost)

Use -NoNewline if using -BackgroundColor.

[Enum]::GetValues([ConsoleColor]) |
ForEach-Object {
	$color = $_.ToString().Trim()
	if (($color -like 'dark*') -or ($color -like 'black')) {
		Write-Host "`n$color" -ForegroundColor $color
		Write-Host "$color" -ForegroundColor White -BackgroundColor $color -NoNewline
	} else {
		Write-Host "`n$color" -ForegroundColor $color
		Write-Host "$color" -ForegroundColor Black -BackgroundColor $color -NoNewline
	}
}

This will produce non apparent bug. Only the object is filled with background color. But when resizing window, the all line is filled. test

Note

This problem does not occur in the integrated terminal for VSCode.

2reactions
fflatencommented, Jun 27, 2022

Still an issue in 7.3 previews. Able to repro in vscode integrated console, conhost and windows terminal. This is one of the few things where Windows PowerShell 5.1 is superior 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS- background color doesn't fill to top of scrolling div
I have a div (sub area of page with scroll bar) that has some text, an image and a table. The background color...
Read more >
Text background color extends to whole line if wrapped
For me, I primarily see it when the prompt causes the window to scroll. When the window doesn't scroll, it renders correctly. See...
Read more >
The Fixed Background Attachment Hack
I want to keep the background gradient in a fixed position on scroll, so let's apply basic CSS styling to the body that...
Read more >
Dynamic color change while scrolling with CSS - YouTube
With the help of `mix-blend-mode`, the effect where a fixed or sticky element switches colors based on the background it's over is really ......
Read more >
Menu Background Color Change On Scroll With Elementor's ...
My goal is to create a community for Web Designers, Developers, Freelancers, and Elementor enthusiasts to learn the design & business side ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found