Add UseOSCIndicator setting to enable progress indicator in terminal (#14927)
This commit is contained in:
parent
7038373b61
commit
c9d65061af
|
@ -47,6 +47,13 @@ namespace Microsoft.PowerShell
|
|||
}
|
||||
|
||||
_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 @@ namespace Microsoft.PowerShell
|
|||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1688,8 +1688,8 @@ namespace System.Management.Automation.Runspaces
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -2056,6 +2056,7 @@ namespace System.Management.Automation.Runspaces
|
|||
.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")
|
||||
|
@ -2115,6 +2116,7 @@ namespace System.Management.Automation.Runspaces
|
|||
.AddItemScriptBlock(@"""$($_.Style)$($_.Style.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Style")
|
||||
.AddItemProperty(@"MaxWidth")
|
||||
.AddItemProperty(@"View")
|
||||
.AddItemProperty(@"UseOSCIndicator")
|
||||
.EndEntry()
|
||||
.EndList());
|
||||
}
|
||||
|
|
|
@ -290,6 +290,11 @@ namespace System.Management.Automation
|
|||
/// 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>
|
||||
|
|
Loading…
Reference in a new issue