microsoft / microsoft/terminal
Rendering issue with PowerShell Write-Host -BackgroundColor
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
### Windows Terminal version
1.23.13503.0
### Windows build number
10.0.26100.0
### Other Software
PowerShell 7.5.4
### Description
- using background color in PowerShell (7.5.4 or earlier) causes artifacts when the text in the console is moving
- also commands that uses progressbars like copy operatings via PSSession, Enable-WindowsFeature sometimes causing that the operation is still visible on the bottom of the screen while it is already done
### Steps to reproduce
1. Deploy a Windows Server 2025 VM with GUI
2. Run Win+X > Terminal (Admin)
3. Deploy PS 7 using winget: `winget install microsoft.powershell`
4. Update Terminal: `winget upgrade --all`
5. Close Terminal,
6. Run Win+X, open Terminal (Admin), Settings > Set Console default to Terminal, Set PowerShell to PowerShell
7. Paste the script using following code in Terminal using `edit `or `notepad `and save the file.
```
$password = "LS1Setup!"
$feature = @('Microsoft-Hyper-V-Tools-All')
Clear-Host
Write-Host "This is my output message about your password $password" -ForeGroundColor Green -BackgroundColor White
Write-Host "Test 123 Message Lorem Ipsum" -ForeGroundColor Yellow
Write-Host "Test 123 Message Lorem Ipsum" -ForeGroundColor Yellow
Write-Host "Test 123 Message Lorem Ipsum" -ForeGroundColor Yellow
Write-Host "Test 123 Message Lorem Ipsum" -ForeGroundColor Yellow -BackgroundColor Red
Write-Host "Disable Feature: $feature" -ForegroundColor Red
Disable-WindowsOptionalFeature -Online -FeatureName $feature
Write-Host "This is my output message about your password $password" -ForeGroundColor Green -BackgroundColor White
Write-Host "This is my output message about your password $password" -ForeGroundColor Green -BackgroundColor Yellow
Write-Host "This is my output message about your password $password" -ForeGroundColor Green -BackgroundColor Yellow
Write-Host "Enable Feature: $feature" -ForegroundColor Cyan
Enable-WindowsOptionalFeature -Online -FeatureName $feature
Write-Host "This is my output message about your password $password" -ForeGroundColor Green -BackgroundColor White
Write-Host "Test 123 Message Lorem Ipsum Message Lorem IpsumMessage Lorem IpsumMessage Lorem IpsumMessage Lorem IpsumMessage Lorem Ipsum" -ForeGroundColor Yellow -BackgroundColor White
Write-Host "Test 123 Message Lorem Ipsum Message Lorem IpsumMessage Lorem IpsumMessage Lorem IpsumMessage Lorem Ipsum" -ForeGroundColor Yellow
Write-Host "Test 123 Message Lorem Ipsum Message Lorem IpsumMessage Lorem IpsumMessage Lorem IpsumMessage Lorem IpsumMessage Lorem Ipsum" -ForeGroundColor Yellow -BackgroundColor White
Write-Host "Test 123 Message Lorem IpsumMessage Lorem IpsumMessage Lorem IpsumMessage Lorem IpsumMessage Lorem Ipsum" -ForeGroundColor Yellow -BackgroundColor Red
```
### Result
8. Execute the script filein PS7 Terminal Window
### Expected Behavior
the color of the background should only span for the lenght of the string and remain in the same line
when the string is longer the linebreak will color more than one line
### Actual Behavior
in another script I am seeing this behaviour instead
the whole line is colored and it will also break into multiple lines.
Example 1:
Example 2:
Contributor guide
Assessment
This issue has not been assessed yet.