8000 Add UseOSCIndicator setting to enable progress indicator in terminal … · PowerShell/PowerShell@c9d6506 · GitHub
[go: up one dir, main page]

Skip to content

Commit c9d6506

Browse files
authored
Add UseOSCIndicator setting to enable progress indicator in terminal (#14927)
1 parent 7038373 commit c9d6506

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt
4747
}
4848

4949
_pendingProgress = null;
50+
51+
if (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSAnsiProgressFeatureName) && PSStyle.Instance.Progress.UseOSCIndicator)
52+
{
53+
// OSC sequence to turn off progress indicator
54+
// https://github.com/microsoft/terminal/issues/6700
55+
Console.Write("\x1b]9;4;0\x1b\\");
56+
}
5057
}
5158
}
5259

@@ -92,6 +99,21 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt
9299
{
93100
// Update the progress pane only when the timer set up the update flag or WriteProgress is completed.
94101
// As a result, we do not block WriteProgress and whole script and eliminate unnecessary console locks and updates.
102+
if (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSAnsiProgressFeatureName) && PSStyle.Instance.Progress.UseOSCIndicator)
103+
{
104+
int percentComplete = record.PercentComplete;
105+
if (percentComplete < 0)
106+
{
107+
// Write-Progress allows for negative percent complete, but not greater than 100
108+
// but OSC sequence is limited from 0 to 100.
109+
percentComplete = 0;
110+
}
111+
112+
// OSC sequence to turn on progress indicator
113+
// https://github.com/microsoft/terminal/issues/6700
114+
Console.Write($"\x1b]9;4;1;{percentComplete}\x1b\\");
115+
}
116+
95117
_progPane.Show(_pendingProgress);
96118
}
97119
}

src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,8 +1688,8 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_Microsoft_PowerShell_Co
16881688
}
16891689

16901690
private const string PreReleaseStringScriptBlock = @"
1691-
if ($_.PrivateData -and
1692-
$_.PrivateData.ContainsKey('PSData') -and
1691+
if ($_.PrivateData -and
1692+
$_.PrivateData.ContainsKey('PSData') -and
16931693
$_.PrivateData.PSData.ContainsKey('PreRelease'))
16941694
{
16951695
$_.PrivateData.PSData.PreRelease
@@ -2056,6 +2056,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
20562056
.AddItemScriptBlock(@"""$($_.Progress.Style)$($_.Progress.Style.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Progress.Style")
20572057
.AddItemScriptBlock(@"""$($_.Progress.MaxWidth)""", label: "Progress.MaxWidth")
20582058
.AddItemScriptBlock(@"""$($_.Progress.View)""", label: "Progress.View")
2059+
.AddItemScriptBlock(@"""$($_.Progress.UseOSCIndicator)""", label: "Progress.UseOSCIndicator")
20592060
.AddItemScriptBlock(@"""$($_.Foreground.Black)$($_.Foreground.Black.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Foreground.Black")
20602061
.AddItemScriptBlock(@"""$($_.Foreground.White)$($_.Foreground.White.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Foreground.White")
20612062
.AddItemScriptBlock(@"""$($_.Foreground.DarkGray)$($_.Foreground.DarkGray.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Foreground.DarkGray")
@@ -2115,6 +2116,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
21152116
.AddItemScriptBlock(@"""$($_.Style)$($_.Style.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Style")
21162117
.AddItemProperty(@"MaxWidth")
21172118
.AddItemProperty(@"View")
2119+
.AddItemProperty(@"UseOSCIndicator")
21182120
.EndEntry()
21192121
.EndList());
21202122
}

src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ public sealed class ProgressConfiguration
290290
/// Gets or sets the view for progress bar.
291291
/// </summary>
292292
public ProgressView View { get; set; } = ProgressView.Minimal;
293+
294+
/// <summary>
295+
/// Gets or sets a value indicating whether to use Operating System Command (OSC) control sequences 'ESC ]9;4;' to show indicator in terminal.
296+
/// </summary>
297+
public bool UseOSCIndicator { get; set; } = false;
293298
}
294299

295300
/// <summary>

0 commit comments

Comments
 (0)
0