question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$PsStyle.OutputFormatting = PlainText is ineffective when host is not 'ConsoleHost'

See original GitHub issue

Prerequisites

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

Name                           Value
----                           -----
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. image

.Net Interactive notebook

image

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. image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
daxian-dbwcommented, Dec 17, 2021

Quote the discussion between @jhoneill and me from https://github.com/PowerShell/PowerShell/issues/16635#issuecomment-996901232

just so I’m clear, although it’s a change in PowerShell itself that caused it, the fix can only come from the people who produce the hosts?

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+.

1reaction
jhoneillcommented, Jan 5, 2022

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.

image

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found