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

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

Closed
5 tasks done
jhoneill opened this issue Dec 17, 2021 · 18 comments
Closed
5 tasks done
Labels
Resolution-External The issue is caused by external component(s). WG-Engine-Format WG-Interactive-Console the console experience

Comments

@jhoneill
Copy link

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

�[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.
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

@jhoneill jhoneill added the Needs-Triage The issue is new and needs to be triaged by a work group. label Dec 17, 2021
@237dmitry
Copy link

237dmitry commented Dec 17, 2021

I do not know. In Windows Console Host and in VSCode all are working as expected. If I set to 'PlainText' the coloring disappeared in entire console screen.

@jhoneill
Copy link
Author

@237dmitry
In VS code does the drop down say "pwsh" or "PowerShell Integrated Console" ?
For me, it works fine if it is pwsh, (just the same as if I do [win key] [r] pwsh, or if I use Windows Terminal) - that's the bottom picture, but if it is the "PowerShell Integrated Console" I get the middle picture.

@237dmitry
Copy link

237dmitry commented Dec 17, 2021

Ah, sorry, I was too hasty. In VSCode coloring is disappeared AFTER setting 'PlainText'. All strings before are still colored.

ss-20211217150552

ss-20211217151544

@jhoneill
Copy link
Author

jhoneill commented Dec 17, 2021

OK, I understand now, yes that looks right in a pwsh pane. My issue is the integrated one

@daxian-dbw
Copy link
Member

VSCode integrated console and PowerShell notebook use different hosts, which haven't been updated to work with $PSStyle. Can you maybe open separate issues in .NET Interactive and PSES repos about this?

@daxian-dbw
Copy link
Member

daxian-dbw commented Dec 17, 2021

Quote the discussion between @jhoneill and me from #16635 (comment)

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

@jhoneill
Copy link
Author

jhoneill commented 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.

@JustinGrote
Copy link
Contributor

It seems to me that if a host could declare or be constructed what formats it supports (plaintext only, console emits, ANSI support), then Powershell should send that output to the host and do that work, and the host can either pass it thorugh or do with it what it wants.

@ALIENQuake
Copy link

@daxian-dbw FWIW, I'm facing this issue using SAPIEN PowerShell Studio.

@jhoneill
Copy link
Author

Looking for something else this is fixed with the newest PowerShell integrated console in VSCode, but the problem remains in .NET Interactive.

@daxian-dbw
Copy link
Member

@jhoneill PowerShell integrated console started to wrap a console host instance internally. The .NET Interactive cannot wrap console host within it, because it's not facing a terminal, but the .NET Interactive stdin/stdout channel.

@jhoneill
Copy link
Author

@daxian-dbw so something that works that way can't get clean output then ?

@daxian-dbw
Copy link
Member

The PowerShell sub-kernel host needs to be updated to strip off the VT sequences properly as controlled by $PSStyle, and that's not done yet :(

@jhoneill
Copy link
Author

But it will be done at some point ?

@simonsabin
Copy link

The PowerShell sub-kernel host needs to be updated to strip off the VT sequences properly as controlled by $PSStyle, and that's not done yet :(

Should that be a switch passed in via pwsh, to control stripping of characters when pwsh called directly

@theJasonHelmick
Copy link
Collaborator

The Working Group has reviewed this issue and agrees it should be filed with .Net Interactive. For discussions regarding the design of PSStyle and it implementation, please open a separate issue.

@theJasonHelmick theJasonHelmick added Resolution-Answered The question is answered. and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Oct 12, 2022
@daxian-dbw daxian-dbw added Resolution-External The issue is caused by external component(s). and removed Resolution-Answered The question is answered. labels Oct 12, 2022
@ghost
Copy link

ghost commented Oct 13, 2022

This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.

@ghost ghost closed this as completed Oct 13, 2022
@jhoneill
Copy link
Author

@theJasonHelmick What troubles me here is: Is .NET interactive the only host with any meaningful user-base which needs to take on the extra work to integrate with PowerShell, or are there a few, or potentially many ? For small numbers filing an issue with them is the right course. For large numbers the solution should be coming from the PowerShell team. I don't know of any others so I'm happy with this marked as external and closed, at least for now. We may need to re-visit but no sense it getting overly worried because it is more likely we won't.
,

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-External The issue is caused by external component(s). WG-Engine-Format WG-Interactive-Console the console experience
Projects
None yet
Development

No branches or pull requests

8 participants