You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write-Host-ForegroundColor / -BackgroundColor don't respect in-session $PSStyle.OutputRendering = 'PlainText', respect it via NO_COLOR only on Unix #21168
I don't know whether the intent is for Write-Host -Fore/BackgroundColor to respect $PSStyle.OutputRendering = 'PlainText' or not - arguably, it should.
Update: Arguably, it should respect all modes, so that 'Host' can be used to use color only when printing to the terminal, and 'ANSI' to request unconditional coloring.
De facto, it currently isn't respected - ever - on Windows, and only situationally on Unix-like platforms
& {
# A preexisting NO_COLOR environment variable sets `$PSStyle.OutputRendering = 'PlainText'` in the session# created by the CLI call.$env:NO_COLOR=1
pwsh -noprofile -c 'Write-Host -ForegroundColor Blue hi'$env:NO_COLOR=$null
}
& {
# Set `$PSStyle.OutputRendering = 'PlainText'` in-session$prev=$PSStyle.OutputRendering$PSStyle.OutputRendering='PlainText'Write-Host-ForegroundColor Blue hi
$PSStyle.OutputRendering=$prev
}
Expected behavior
Either both 'hi' instances should be blue (as currently on Windows), or, preferably, both should use the default foreground color.
Actual behavior
On Windows, both 'hi' instances are blue.
On Unix-like platforms, the first 'hi' uses the default color, and the second one is blue.