8000 Add UseOSCIndicator setting to enable progress indicator in terminal by SteveL-MSFT · Pull Request #14927 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Add UseOSCIndicator setting to enable progress indicator in terminal #14927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 12, 2021

Conversation

SteveL-MSFT
Copy link
Member
@SteveL-MSFT SteveL-MSFT commented Mar 1, 2021

PR Summary

Add new $PSStyle.Progress.UseOSCIndicator setting to use conemu's OSC indicator to show progress in the terminal window, which is also supported by Windows Terminal. Since this is a custom OSC that isn't widely supported, it defaults to $false. Since this is an advanced setting not supported by many terminals, had to give it a technical name. iTerm2, for example, uses ESC]9; as a notification OSC sequence so you get a pop-up dialog instead of progress.

This is enabled as part of PSAnsiProgress experimental feature

image

cc @DHowett

PR Context

PR Checklist

@bergmeister
Copy link
Contributor

Whilst one wouldn't want things special cased and hard-coded to terminals, one can actually detect if PowerShell is hosted within ConEmu via environment variables.
Therefore what do you think about a best effort approach of trying to detect well known terminals like ConEmu or the Windows terminal and have a different default if and only if it can be detected with confidence.

@SteveL-MSFT
Copy link
Member Author

@bergmeister does ConEmu have a big enough customer base to warrant such code? Also, does every version of ConEmu support it? In the case of Windows Terminal, we'd have to check that it's newer than a specific version to turn it on by default.

@JustinGrote
Copy link
Contributor
JustinGrote commented Mar 2, 2021

@SteveL-MSFT @bergmeister I worry about doing automatic terminal detection being a slippery slope of the team having to support all kinds of terminal quirks long-term, when it's easy enough to do the detection in a user profile. Especially when being done with something as arbitrary as environment variables vs. some sort of standard cross-platform terminal feature detection process (which doesn't exist to my knowledge)

This kind of detection could also easily be done in a separate module that manages PSStyle, I don't think it should be part of the core PS codebase however.

@daxian-dbw
Copy link
Member

@SteveL-MSFT It would be nice if you can add screenshot or GIF to show how this looks in Windows Terminal.

}

// 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

…e.cs

Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
@SteveL-MSFT
Copy link
Member Author

@daxian-dbw added a gif, you can see it in the upper left of the tab. It's just a little circle that fills in based on % complete

Copy link
@anmenaga anmenaga left a comment

Choose a reason for hiding this comment

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

LGTM

@anmenaga anmenaga added CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log CL-Experimental Indicates that a PR should be marked as an Experimental Feature in the Change Log and removed CL-Experimental Indicates that a PR should be marked as an Experimental Feature in the Change Log labels Mar 12, 2021
@anmenaga anmenaga changed the title Add $PSStyle.Progress.UseOSCIndicator to enable progress indicator in terminal Add UseOSCIndicator setting to enable progress indicator in terminal Mar 12, 2021
@anmenaga
Copy link

Changed PR title so that changelog generation script won't have problems with it.

@anmenaga anmenaga merged commit c9d6506 into PowerShell:master Mar 12, 2021
@SteveL-MSFT SteveL-MSFT deleted the progress-indicator branch March 12, 2021 03:31
@ghost
Copy link
ghost commented Mar 16, 2021

🎉v7.2.0-preview.4 has been released which incorporates this pull request.:tada:

Handy links:

@sba923
Copy link
Contributor
sba923 commented Apr 18, 2021

Given that the OSC progress indicator is a "write-only" thing, there are a number of scenarios where the result is not what one would expect IMVHO:

  1. a;b;c;d one-liner where a sets the indicator to "indeterminate" using OSC9;4;3;100BEL, b launches a script that uses Write-Progress, c performs some time-consuming actions, and d resets the indicator using OSC9;4;0;100BEL: the "indeterminate" indicator is overwritten by the Write-Progress so during the execution of c the indicator is not the "indeterminate" one but the "0%" one
  2. If a script shows its progress using Write-Progress and uses Compress-Archive, the indicator set by the former is overwritten by the one set by the latter, so the indicator that's visible most of the time is 0% since that's what it's reset to at the end of the Compress-Archive

This can be experimented with something like this:

param([int] $Count = 10, [int] $Delay = 10, [switch] $Archive)

for ($i=0; $i -lt $Count; $i++)
{
    Write-Host ("{0}/{1}" -f $i, $Count)
    Write-Progress -Activity 'Activity' -Status 'Status' -PercentComplete (100 * ($i+1) / $Count)
    if ($Archive)
    {
        Remove-Item c:/tmp/foo.zip -ea 0
        Compress-Archive -destination c:/tmp/foo.zip C:\Users\steph\OneDrive\Images\*.cr2
    }
    Start-Sleep -Seconds $Delay
}
Write-Progress -Activity 'Activity' -Status 'Status' -Completed

I think what we need is some global stack-based encapsulation of the indicator, where the latest desired indicator is "pushed" to the top of the stack, and the indicator is restored to the previous state on a "pop" operation.

@DHowett
Copy link
DHowett commented Apr 18, 2021

This needs to be solved for all nested and coterminous progress operations regardless of OSC indication. OSC indication being mixed up is only one symptom of the underlying issue. 😄

@sba923
Copy link
Contributor
sba923 commented Apr 19, 2021

This needs to be solved for all nested and coterminous progress operations regardless of OSC indication. OSC indication being mixed up is only one symptom of the underlying issue. 😄

Where is discussed / tracked?

Are the a / d parts of my scenario #1 covered?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0