$PsStyle.OutputFormatting = PlainText is ineffective when host is not 'ConsoleHost'
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Setting $PSStyle.OutputRendering = “PlainText” removes colour. However it only seems to do so if the $host.name
is ConsoleHost
so using a .Net Interactive notebook (which doesn’t load the profile as a way to set psstyle preferences) or the the PowerShell Integrated console in VS Code. (“.NET Interactive Host” and " Visual Studio Code Host" respectively)
Expected behavior
Setting $PSStyle.OutputRendering = "PlainText" removes colour
Actual behavior
Setting $PSStyle.OutputRendering = "PlainText" does not removes colour when the host is not "Consolehost" see visuals
Error details
No message
Environment data
[32;1mName Value[0m
[32;1m---- -----[0m
PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.19042
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
Below both show labels in green despite plain text being selected.
.Net Interactive notebook
PowerShell Integrated Console in VS Code.
In the console host (Windows terminal, legacy console, and pwsh in VS Code outside the integrated vs code console). plain text removes the green colouring.
Issue Analytics
- State:
- Created 2 years ago
- Comments:18 (6 by maintainers)
Top Results From Across the Web
$PsStyle.OutputFormatting = PlainText is ineffective when host is ...
$PsStyle.OutputFormatting = PlainText is ineffective when host is not 'ConsoleHost' · Summary · Jobs. Rebase · Run details. Usage · Workflow file.
Read more >Using PowerShell with $PSStyle
In this post, I show you how you can use ANSI rendering to control text decorations, such as color and font styling, in...
Read more >about ANSI terminals - PowerShell
Describes the features of PowerShell that use ANSI escape sequences and the terminal hosts that support them.
Read more >Untitled
Psstyle powershell How to remove special characters in string in powershell? ... OutputFormatting = PlainText is ineffective when host is … Web1. Dez....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Quote the discussion between @jhoneill and me from https://github.com/PowerShell/PowerShell/issues/16635#issuecomment-996901232
Unfortunately, yes. In PowerShell itself, the work that strips off the ANSI code is done in ConsoleHost, and that makes it necessary for other host to do something similar.
But you made me start to think, maybe that’s not the right design, maybe that should be done in formatting before sending the payload to host … there could be other applications that hosts PowerShell out there in the wild, and requiring extra work to their host after upgrading to PS 7.2 is not a pleasant ask for sure.
We may want to rethink about where to strip off the ANSI code. Does this work have to be done in host implementation? If not, it’s better to do it in PowerShell formatting, so various hosts out in the wild don’t need to change for
$PSStyle
to work properly when upgrading to PS 7.2+.There seem to be other problems relating to different hosts, which suggest - per @daxian-dbw above - shifting this out of the host is a good idea.
The screen shot below is using a .NET interactive notebook. Red is used in the right most column to say "EXCEPT in these environments. The section labelled 1 in the screen, shows without colour the environment name fits on one line but when colour is added the same text is split over two lines - I assume because the codes for “foreground red” and “reset” are treated as visible characters. I’ve mentioned on #16700 that because the reset has moved down a line Panettone service gets trapped between the begin and end of colour for shared services pre-release, turning it red.
On the bottom row, blue is used to highlight some types of action and (2) shows the codes for “foreground blue” and “reset” have reduced padding before the next column.
Neither (1) nor (2) occurs in the default host, but making people who create other hosts bring over multiple pieces of functionality is not ideal.