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

Write-Host -ForegroundColor / -BackgroundColor don't respect in-session $PSStyle.OutputRendering = 'PlainText', respect it via NO_COLOR only on Unix #21168

Open
5 tasks done
mklement0 opened this issue Jan 31, 2024 · 1 comment · May be fixed by #21188
Assignees
Labels
In-PR Indicates that a PR is out for the issue Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@mklement0
Copy link
Contributor

mklement0 commented Jan 31, 2024

Prerequisites

Steps to reproduce

Note:

  • I don't know whether the intent is for Write-Host -Fore/BackgroundColor to respect $PSStyle.OutputRendering = 'PlainText' or not - arguably, it should.

  • De facto, it currently isn't respected - consistently - on Windows and is situationally respected 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.

Error details

No response

Environment data

PowerShell 7.4.1

Visuals

No response

@mklement0 mklement0 added the Needs-Triage The issue is new and needs to be triaged by a work group. label Jan 31, 2024
@mklement0 mklement0 changed the title Write-Host -ForegroundColor / BackgroundColor don't respect in-session $PSStyle.OutputRendering = 'PlainText', respect it via NO_COLOR only on Unix Write-Host -ForegroundColor / -BackgroundColor don't respect in-session $PSStyle.OutputRendering = 'PlainText', respect it via NO_COLOR only on Unix Jan 31, 2024
@SteveL-MSFT
Copy link
Member

For Windows, part of the problem seems to be that there is still Windows specific code paths (originally from Windows PowerShell) to read/write directly to the console which is not respecting PSStyle. Given that .NET has evolved and Windows Terminal is now default, we should consider removing all that code and just let .NET do the work.

As for Write-Host itself, I see where it ends up writing to PSHost and it just needs to respect PlainText, fix coming.

@SteveL-MSFT SteveL-MSFT self-assigned this Feb 5, 2024
@SteveL-MSFT SteveL-MSFT linked a pull request Feb 6, 2024 that will close this issue
22 tasks
@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR Indicates that a PR is out for the issue label Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In-PR Indicates that a PR is out for the issue Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants