Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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 @@ -3,14 +3,15 @@

using System;
using System.Management.Automation;
using System.Management.Automation.Host;
using System.Threading;

using Dbg = System.Management.Automation.Diagnostics;

namespace Microsoft.PowerShell
{
internal partial
class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInterface
class ConsoleHostUserInterface : PSHostUserInterface
{
/// <summary>
/// Called at the end of a prompt loop to take down any progress display that might have appeared and purge any
Expand Down Expand Up @@ -48,7 +49,7 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt

_pendingProgress = null;

if (SupportsVirtualTerminal && PSStyle.Instance.Progress.UseOSCIndicator)
if (SupportsVirtualTerminal && !PSHost.IsStdOutputRedirected && PSStyle.Instance.Progress.UseOSCIndicator)
{
// OSC sequence to turn off progress indicator
// https://github.com/microsoft/terminal/issues/6700
Expand Down Expand Up @@ -99,7 +100,7 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt
{
// Update the progress pane only when the timer set up the update flag or WriteProgress is completed.
// As a result, we do not block WriteProgress and whole script and eliminate unnecessary console locks and updates.
if (SupportsVirtualTerminal && PSStyle.Instance.Progress.UseOSCIndicator)
if (SupportsVirtualTerminal && !PSHost.IsStdOutputRedirected && PSStyle.Instance.Progress.UseOSCIndicator)
{
int percentComplete = record.PercentComplete;
if (percentComplete < 0)
Expand Down
8 changes: 8 additions & 0 deletions 8 test/powershell/engine/Formatting/PSStyle.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ Describe 'Tests for $PSStyle automatic variable' {
$PSStyle.Progress.MaxWidth = $maxWidth
}
}

It 'Do not use OSC indicator when the stdout is redirected' {
$pwsh = Join-Path $PSHOME 'pwsh'

## In the case that the stdout is redirected, pwsh should not write the OSC indicator Ansi sequence.
$result = & $pwsh -noprofile -Command { $PSStyle.Progress.UseOSCIndicator = $true; 'hello'} | Format-List
$result | Out-String -Stream | Should -BeExactly 'hello'
}
}

Describe 'Handle strings with escape sequences in formatting' {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.