Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ public override void WriteDebugLine(string message)
{
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
{
Expand Down Expand Up @@ -1276,7 +1276,7 @@ public override void WriteVerboseLine(string message)
{
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
{
Expand Down Expand Up @@ -1320,7 +1320,7 @@ public override void WriteWarningLine(string message)
{
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
{
Expand Down
5 changes: 2 additions & 3 deletions src/System.Management.Automation/engine/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1617,13 +1617,12 @@ internal enum FormatStyle
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;
}
Expand Down
10 changes: 0 additions & 10 deletions test/powershell/engine/Formatting/OutputRendering.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 @(
Expand Down