diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs index 50dedf410a7..406c36c8a00 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs @@ -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\\"); + } } } @@ -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 + Console.Write($"\x1b]9;4;1;{percentComplete}\x1b\\"); + } + _progPane.Show(_pendingProgress); } } diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index d9763164679..c0a30061524 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -1687,8 +1687,8 @@ private static IEnumerable 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 @@ -2055,6 +2055,7 @@ private static IEnumerable 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") @@ -2114,6 +2115,7 @@ private static IEnumerable ViewsOf_System_Management_Autom .AddItemScriptBlock(@"""$($_.Style)$($_.Style.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Style") .AddItemProperty(@"MaxWidth") .AddItemProperty(@"View") + .AddItemProperty(@"UseOSCIndicator") .EndEntry() .EndList()); } diff --git a/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs b/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs index aa00bdf9e18..b8e1890b37f 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs @@ -290,6 +290,11 @@ public sealed class ProgressConfiguration /// Gets or sets the view for progress bar. /// public ProgressView View { get; set; } = ProgressView.Minimal; + + /// + /// Gets or sets a value indicating whether to use Operating System Command (OSC) control sequences 'ESC ]9;4;' to show indicator in terminal. + /// + public bool UseOSCIndicator { get; set; } = false; } ///