Powershell: UI Back Ground Color not honored after Host-Clear

Created on 18 Sep 2018  路  3Comments  路  Source: PowerShell/PowerShell

As of RS5, why does Clear-Host now reset the window to the default colors?

If I have the following in my profile:

$Host.UI-RawUI.BackGroundColor = 'DarkRed'

Then I issue a Clear-Host

The Background color is reset to the window default.

Prior to RS5, the background color would remain Dark Red.

I use this to determine if I'm in a shell with administrative permissions and then change the background color accordingly. However, with RS5 this is broken (note, my script has not changed)

Steps to reproduce

  1. Execute: $Host.UI-RawUI.BackGroundColor = 'DarkRed'
  2. Execute: Clear-Host

Expected behavior

Background color should be Dark Red

Actual behavior

Background color reverts to the default color defined in the Window settings

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.17754.1
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17754.1
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Issue-Bug WG-Interactive-PSReadLine

All 3 comments

@W0GER The repo is only for Power Core. For Windows PowerShell please report to UserVoice site or use Feedback tool in Windows 10 Preview builds.

Can you reproduce the issue with PowerShell Core latest build?

This does not reproduce in PS Core 6.1 RC1. Host retains red background color, and executing Clear-Host causes the entire background to be filled with the newly selected color.

Name                           Value
----                           -----
PSVersion                      6.1.0-rc.1
PSEdition                      Core
GitCommitId                    6.1.0-rc.1
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I can reproduce in RS5 with PS Core 6.1. It doesn't seem to be related to Clear-Host though see the following:

image

If I remove PSReadLine, then the background stays, so this seems to be a PSReadLine bug.

Was this page helpful?
0 / 5 - 0 ratings