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 @@ -47,6 +47,13 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt
}

_pendingProgress = null;

if (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSAnsiProgressFeatureName) && PSStyle.Instance.Progress.UseOSCIndicator)
{
// OSC sequence to turn off progress indicator
// https://github.com/microsoft/terminal/issues/6700
Console.Write("\x1b]9;4;0\x1b\\");
}
}
}

Expand Down Expand Up @@ -92,6 +99,21 @@ 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 (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSAnsiProgressFeatureName) && PSStyle.Instance.Progress.UseOSCIndicator)
{
int percentComplete = record.PercentComplete;
if (percentComplete < 0)
{
// Write-Progress allows for negative percent complete, but not greater than 100
// but OSC sequence is limited from 0 to 100.
percentComplete = 0;
}

// OSC sequence to turn on progress indicator
// https://github.com/microsoft/terminal/issues/6700
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an official document for the OSC sequences supported in Windows Terminal?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None I could find other than the github issue

Console.Write($"\x1b]9;4;1;{percentComplete}\x1b\\");
}

_progPane.Show(_pendingProgress);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1687,8 +1687,8 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_Microsoft_PowerShell_Co
}

private const string PreReleaseStringScriptBlock = @"
if ($_.PrivateData -and
$_.PrivateData.ContainsKey('PSData') -and
if ($_.PrivateData -and
$_.PrivateData.ContainsKey('PSData') -and
$_.PrivateData.PSData.ContainsKey('PreRelease'))
{
$_.PrivateData.PSData.PreRelease
Expand Down Expand Up @@ -2055,6 +2055,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
.AddItemScriptBlock(@"""$($_.Progress.Style)$($_.Progress.Style.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Progress.Style")
.AddItemScriptBlock(@"""$($_.Progress.MaxWidth)""", label: "Progress.MaxWidth")
.AddItemScriptBlock(@"""$($_.Progress.View)""", label: "Progress.View")
.AddItemScriptBlock(@"""$($_.Progress.UseOSCIndicator)""", label: "Progress.UseOSCIndicator")
.AddItemScriptBlock(@"""$($_.Foreground.Black)$($_.Foreground.Black.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Foreground.Black")
.AddItemScriptBlock(@"""$($_.Foreground.White)$($_.Foreground.White.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Foreground.White")
.AddItemScriptBlock(@"""$($_.Foreground.DarkGray)$($_.Foreground.DarkGray.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Foreground.DarkGray")
Expand Down Expand Up @@ -2114,6 +2115,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
.AddItemScriptBlock(@"""$($_.Style)$($_.Style.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Style")
.AddItemProperty(@"MaxWidth")
.AddItemProperty(@"View")
.AddItemProperty(@"UseOSCIndicator")
.EndEntry()
.EndList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ public sealed class ProgressConfiguration
/// Gets or sets the view for progress bar.
/// </summary>
public ProgressView View { get; set; } = ProgressView.Minimal;

/// <summary>
/// Gets or sets a value indicating whether to use Operating System Command (OSC) control sequences 'ESC ]9;4;' to show indicator in terminal.
/// </summary>
public bool UseOSCIndicator { get; set; } = false;
}

/// <summary>
Expand Down