-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Enable simpler ANSI formatting via $PSStyle
and support suppressing ANSI output
#13758
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
Conversation
57589ea
to
da999d9
Compare
Still need to add tests |
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment. |
src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs
Outdated
Show resolved
Hide resolved
Still need to have WriteVerbose, etc... use the $PSStyle settings before taking this out of draft |
src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs
Outdated
Show resolved
Hide resolved
I really like this PR! It will be super useful to me! |
src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Publish my comments so far, will continue to review.
src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/hostifaces/InternalHostUserInterface.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/ILineOutput.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs
Outdated
Show resolved
Hide resolved
So
will output red colored string. In time of evaluating the string we already know values of all constants - SupportsVirtualTerminal, isHost, Console.IsOutputRedirected. If so why do we need the filtering at all if we can return $null at the evaluating time if we do not need the ANSI value? |
@iSazonov |
if (!InternalTestHooks.BypassOutputRedirectionCheck && | ||
((PSStyle.Instance.OutputRendering == OutputRendering.PlainText) || | ||
(formatStyle == FormatStyle.Error && Console.IsErrorRedirected) || | ||
(formatStyle != FormatStyle.Error && Console.IsOutputRedirected))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveL-MSFT, this method currently directly check on Console.IsErrorRedirected
and Console.IsOutputRedirected
. I think we shouldn't directly check on those in PowerShell engine, but should instead have separate parameters for the caller to provide that information. The engine should not assume there is a console available, and it's up to the host implementation to pass in whether there is error/output redirection when calling this method.
I've put this comment in the tracking issue #14387, so you can fix it in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveL-MSFT I say that $PSStyle could not be a const and be evaluated - as result we have no need to filter out escapes because $PSStyle would return $null if user turns off coloring or terminal does not support escapes and so on. |
@iSazonov The PowerShell engine doesn't know if the output/error is being reidrected. It cannot depedn on Take the host implementation of the PowerShell sub kernel (jupyter kernel) in .NET Interactive as an instance, it's a console application, and the process's output/error streams are always redirected to send to the frontend -- jupyter notebook, which is capable of handling ANSI sequences. So, in this case, even thought To summarize, the host implementation has the final call on whether ANSI sequences should be stripped off or not, and that's why I opened #14387. |
Why can't PowerShell engine get this information from the host implementation?
So PowerShell engine can get get this information from the host implementation? |
I don't know how that would work and how well that would work if it works.
|
🎉 Handy links: |
These changes don't seem to work in the Integrated Console: #14435 |
PR Summary
See #13071 for details.
$PSStyle
automatic variable to get or set ANSI escape sequences associated with text decoration$PSStyle
to help users see what the output would look like using one of the colors/attributes. Note that current design choice is to automatically show nested types in$PSStyle
as I expect users dumping that variable are interested in all the choices.After this is merged:
__SuppressAnsiExscapeSequences
code as it's no longer needed$PSStyle
PR Context
Fix #13071
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.PSAnsiRendering