Skip to content
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

Use ANSI codes to report progress #11432

Closed
albertlarsan68 opened this issue Nov 28, 2022 · 7 comments · Fixed by #14615
Closed

Use ANSI codes to report progress #11432

albertlarsan68 opened this issue Nov 28, 2022 · 7 comments · Fixed by #14615
Assignees
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@albertlarsan68
Copy link
Member

albertlarsan68 commented Nov 28, 2022

Problem

When the terminal is not in focus, there is no way to know the progress state of the compilation.

Proposed Solution

There exist escape codes that allow control of a "progress meter", that for example is shown on the taskbar in Windows.
Winget uses them, and the implementation can be seen at https://github.com/microsoft/winget-cli/blob/master/src/AppInstallerCLICore/VTSupport.cpp. It mostly consists of adding the correct progress number, and clean up after the end.

Notes

I volunteer to make this change to this repo.

@albertlarsan68 albertlarsan68 added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Nov 28, 2022
@albertlarsan68
Copy link
Member Author

@rustbot label +A-console-output

@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 2022

Error: The feature relabel is not enabled in this repository.
To enable it add its section in the triagebot.toml in the root of the repository.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@epage epage added the A-console-output Area: Terminal output, colors, progress bar, etc. label Nov 28, 2022
@albertlarsan68
Copy link
Member Author

https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC is the documentation page for it. Windows Terminal supports it, which makes it a worthwhile addition for both Windows and Linux, as WSL exists.

@albertlarsan68
Copy link
Member Author

@rustbot claim

bors added a commit that referenced this issue Dec 18, 2022
Enable triagebot's relabel functionality

### What does this PR try to resolve?

This fixes the following failure that rustbot currently posts whenever someone tries to use "<b>`@</b><b>rustbot</b>` label" in this repository.

> **Error**: The feature `relabel` is not enabled in this repository.
> To enable it add its section in the `triagebot.toml` in the root of the repository.

Unauthenticated relabel has been enabled in rust-lang/rust for nearly 4 years. People overwhelmingly use it in good faith.

<br>

### How should we test and review this PR?

Compare against https://github.com/rust-lang/rust/blob/1.66.0/triagebot.toml.

Also skim through the 7 pages of labels on https://github.com/rust-lang/cargo/labels, whether it makes sense the ones I decided to allow arbitrary GitHub users to apply.

<br>

### Additional information

Attempted uses of "<b>`@</b><b>rustbot</b>` label", that failed, but this PR would allow:

- #10343 (comment)
- #10243 (comment)
- #9982 (comment)
- #9128 (comment)
- #9067 (comment)
- #8441 (comment)
- #11432 (comment)
- #8841 (comment)
- #10820 (comment)
- #10572 (comment)
- #9114 (comment)
- #8980 (comment)
- #9064 (comment)
- #8726 (comment)
- #8089 (comment)
@weihanglo weihanglo added the S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. label May 11, 2023
@weihanglo
Copy link
Member

Triage: This is a cool enhancement but we need to be careful to not break people's emulators with unsupported escape code. In #11436 the author did some initial research, we'd like to see more info got collected back.


Copied from #11436 (comment):

Current testing progress:

Terminal Support
Windows Terminal
Git MinTTY ✅ (but reset only happens when progress is set to 0)
Alacritty ❌ (Feature seemingly refused)

Procedure:
run echo -e "\e]9;4;1;50\e\\" for Linux-like, or copy the line below for Powershell Core and paste it at the prompt.
Reset with echo -e "\e]9;4;0;50\e\\" or the second line. If that doesn't work replace the 50 with a 0.

"`e]9;4;1;50`e\"
"`e]9;4;0;50`e\"

Suggestions for future survey (#11436 (comment)):

Two columns in the table:

  • Support the display of the progress bar or not.
  • If not supported, would it break things or just ignore the unrecognized escape code?

@epage
Copy link
Contributor

epage commented Nov 8, 2023

Following the pattern of #12889 might offer a route for us to move forward with this

  • Have an allowlist of terminals
  • Have a term.progress for explicitly enabling / disabling it to workaround the allowlist until a new release is out

This also makes me wonder about using escape codes to set the window / tab title during the build to report progress.

@weihanglo
Copy link
Member

I am totally okay if it can be turned off.

Found this resource of escape code we might want to support: https://tldp.org/HOWTO/Xterm-Title.html, though it's a bit old (1999).

github-merge-queue bot pushed a commit that referenced this issue Mar 10, 2025
### What does this PR try to resolve?

A few terminal emulators support progress output to Windows taskbar.
`winget` uses this to show install progress.

Notably, Windows Terminal [recently (2020) added
support](microsoft/terminal#8055) for ANSI codes
[specified](https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC)
in ConEmu (another terminal emulator for Windows) documentation. Also,
in "[Learn
Windows](https://learn.microsoft.com/en-us/windows/terminal/tutorials/progress-bar-sequences)".

I've found the previous attempt to add this feature:
#11436

As per @weihanglo's request, I've added the config option to
enable/disable this feature. **It's enabled on supported terminal
emulators.**

Fixes #11432

FCP:
#14615 (comment)

### How should we test and review this PR?

Run `cargo build` in Windows Terminal with configuration option
`term.progress.taskbar` set to `true`.

### Not sure

- [x] Should all the code be `#[cfg(windows)]`? Probably no, because the
feature is also usable in WSL.
> Solved by introducing heuristic based on environment variable set by
terminal

- [ ] If Ctrl+C is pressed, a progressbar will stay in a last state
forever (shown in the ConEmu video). `winget` is also behaves like
alike. I've experimented with `ctrl_c handler` and it's totally fixable.
- [x] `Enabled` is a sensible default for WSL because it works on linux
builds in Windows Terminal too
> Solved by introducing heuristic based on environment variable set by
terminal

- [x] Downloading stage may produce unpleasant blinking due to a rapid
0-100 changes
> Solved by not displaying bar when downloading and using indeterminate
state in other cases so amination don't reset

### TLDR

* An `term.progress.taskbar` option with bool type is added
* On Windows Terminal and ConEmu is enabled by default
* If enabled reports build progress to taskbar icon and/or tab header

### Videos

https://github.com/user-attachments/assets/48bb648a-e819-490e-b3ac-3502bc5f2f3a

https://github.com/user-attachments/assets/1d7ddf7a-34dd-4db1-b654-e64d7170798e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
4 participants