mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add isOutputRedirected parameter to GetFormatStyleString() method (#14397)
This commit is contained in:
@@ -1215,7 +1215,7 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
if (SupportsVirtualTerminal)
|
||||
{
|
||||
WriteLine(Utils.GetFormatStyleString(Utils.FormatStyle.Debug) + StringUtil.Format(ConsoleHostUserInterfaceStrings.DebugFormatString, message) + PSStyle.Instance.Reset);
|
||||
WriteLine(Utils.GetFormatStyleString(Utils.FormatStyle.Debug, Console.IsOutputRedirected) + StringUtil.Format(ConsoleHostUserInterfaceStrings.DebugFormatString, message) + PSStyle.Instance.Reset);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1276,7 +1276,7 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
if (SupportsVirtualTerminal)
|
||||
{
|
||||
WriteLine(Utils.GetFormatStyleString(Utils.FormatStyle.Verbose) + StringUtil.Format(ConsoleHostUserInterfaceStrings.VerboseFormatString, message) + PSStyle.Instance.Reset);
|
||||
WriteLine(Utils.GetFormatStyleString(Utils.FormatStyle.Verbose, Console.IsOutputRedirected) + StringUtil.Format(ConsoleHostUserInterfaceStrings.VerboseFormatString, message) + PSStyle.Instance.Reset);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1320,7 +1320,7 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
if (SupportsVirtualTerminal)
|
||||
{
|
||||
WriteLine(Utils.GetFormatStyleString(Utils.FormatStyle.Warning) + StringUtil.Format(ConsoleHostUserInterfaceStrings.WarningFormatString, message) + PSStyle.Instance.Reset);
|
||||
WriteLine(Utils.GetFormatStyleString(Utils.FormatStyle.Warning, Console.IsOutputRedirected) + StringUtil.Format(ConsoleHostUserInterfaceStrings.WarningFormatString, message) + PSStyle.Instance.Reset);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1617,13 +1617,12 @@ namespace System.Management.Automation
|
||||
Debug,
|
||||
}
|
||||
|
||||
internal static string GetFormatStyleString(FormatStyle formatStyle)
|
||||
internal static string GetFormatStyleString(FormatStyle formatStyle, bool isOutputRedirected)
|
||||
{
|
||||
// redirected console gets plaintext output to preserve existing behavior
|
||||
if (!InternalTestHooks.BypassOutputRedirectionCheck &&
|
||||
((PSStyle.Instance.OutputRendering == OutputRendering.PlainText) ||
|
||||
(formatStyle == FormatStyle.Error && Console.IsErrorRedirected) ||
|
||||
(formatStyle != FormatStyle.Error && Console.IsOutputRedirected)))
|
||||
isOutputRedirected))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,6 @@
|
||||
# Licensed under the MIT License.
|
||||
|
||||
Describe 'OutputRendering tests' {
|
||||
BeforeAll {
|
||||
$th = New-TestHost
|
||||
$rs = [runspacefactory]::Createrunspace($th)
|
||||
$rs.open()
|
||||
$ps = [powershell]::Create()
|
||||
$ps.Runspace = $rs
|
||||
}
|
||||
|
||||
BeforeEach {
|
||||
if ($null -ne $PSStyle) {
|
||||
$oldOutputRendering = $PSStyle.OutputRendering
|
||||
@@ -20,8 +12,6 @@ Describe 'OutputRendering tests' {
|
||||
if ($null -ne $PSStyle) {
|
||||
$PSStyle.OutputRendering = $oldOutputRendering
|
||||
}
|
||||
|
||||
$ps.Commands.Clear()
|
||||
}
|
||||
|
||||
It 'OutputRendering works for "<outputRendering>" to the host' -TestCases @(
|
||||
|
||||
Reference in New Issue
Block a user