Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird foreground color issue with Cmder + PowerShell Core #1899

Closed
1 of 3 tasks
refactorsaurusrex opened this issue Oct 2, 2018 · 7 comments
Closed
1 of 3 tasks

Weird foreground color issue with Cmder + PowerShell Core #1899

refactorsaurusrex opened this issue Oct 2, 2018 · 7 comments

Comments

@refactorsaurusrex
Copy link

refactorsaurusrex commented Oct 2, 2018

Purpose of the issue

  • Bug report (encountered problems/errors)
  • Feature request (request for new functionality)
  • Question

Description of the issue

Out of the box, running PowerShell with Cmder sets the foreground color to white:

cmder good

Today I installed PowerShell Core and created a new Cmder task exactly like the default 'PowerShell as Admin task', but points to pwsh.exe instead of Powershell.exe:

*C:\Program Files\PowerShell\6\pwsh.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -NoExit -Command "Invoke-Expression '. ''%ConEmuDir%\..\profile.ps1'''"

For reasons I don't understand, the foreground color for the PowerShell Core window is green:

cmder bad

While trying to understand why, I spent some time fiddling with the following block of code contained in \vendor\profile.ps1:

[ScriptBlock]$CmderPrompt = {
  $Host.UI.RawUI.ForegroundColor = "White"
  Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
  checkGit($pwd.ProviderPath)
}

Here's where it gets weird. If I change that Write-Host statement to use -ForegroundColor White instead of Green, the foreground color remains permanently white. If I change it to Red, the foreground color remains permanently red. Even weirder: If I leave the original Write-Host statement alone (using the original Green color), but add an additional Write-Host statement above it without a Foregroundcolor parameter, the foreground color remains white. It's as though a Write-Host statement is required in order to maintain the state of $Host.UI.RawUI.ForegroundColor.

Anyone else experiencing this oddity? Am I missing something stupid?

I tried this with Cmder 1.3.5 and 1.3.6 - same result.


Additional Examples:

Results in white foreground color:

[ScriptBlock]$CmderPrompt = {
  $Host.UI.RawUI.ForegroundColor = "White"
  Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor White
  checkGit($pwd.ProviderPath)
}

Also results in white foreground color:

[ScriptBlock]$CmderPrompt = {
  $Host.UI.RawUI.ForegroundColor = "White"
  Write-Host "blah"
  Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
  checkGit($pwd.ProviderPath)
}

Results in red foreground color:

[ScriptBlock]$CmderPrompt = {
  $Host.UI.RawUI.ForegroundColor = "White"
  Write-Host "blah" -ForegroundColor Red
  Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
  checkGit($pwd.ProviderPath)
}
@crutchcorn
Copy link

Having the same issue myself on Windows 10 October update

@CAKEbuilder
Copy link

CAKEbuilder commented Oct 4, 2018

Same issue here. This is a problem on two separate machines of mine after updating with v1809 of Win10.

@refactorsaurusrex
Copy link
Author

Ditto. After updating to the latest Windows 10 release, the foreground color is green both with PS5 and PS6.

@mattvperry
Copy link

The workaround I will use involves a unicode no width char:

[ScriptBlock]$CmderPrompt = {
  $Host.UI.RawUI.ForegroundColor = "White"
  Write-Host -NoNewline "$([char]0x200B)"
  Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
  checkGit($pwd.ProviderPath)
}

@chawyehsu
Copy link

chawyehsu commented Nov 24, 2018

Could you guys tell me if this issue would be gone after installing PSReadLine v1.2:

Install-Module -Name PSReadLine -RequiredVersion 1.2 -Scope CurrentUser -Force -SkipPublisherCheck

I guess it's a likely a complex issue of PSReadLine2 and Cmder, maybe related to PowerShell/PSReadLine#818.

Besides, thanks @mattvperry for the workaround! 👍

@crutchcorn
Copy link

@h404bi This seems to have fixed it for me.

@skycommand
Copy link

skycommand commented Mar 12, 2019

Thanks for the report, @refactorsaurusrex – it helped me fix two of my problems in one go. First, the color, and second, the absence of "PS" before the prompt. I added the third line, seen below, to the code:

[ScriptBlock]$CmderPrompt = {
    $Host.UI.RawUI.ForegroundColor = "White"
    Microsoft.PowerShell.Utility\Write-Host "PS " -NoNewline  # <!-- this line is added
    Microsoft.PowerShell.Utility\Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
    checkGit($pwd.ProviderPath)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants