Skip to content

Commit 0b5d075

Browse files
authored
Add a tutorial for using the progress bar (#704)
As noted in #514 closes #514 xref microsoft/terminal#6700
1 parent f326e88 commit 0b5d075

2 files changed

Lines changed: 93 additions & 2 deletions

File tree

‎TerminalDocs/TOC.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- name: Windows Terminal
2-
items:
2+
items:
33
- name: Overview
44
href: index.md
55
- name: Install
@@ -56,6 +56,8 @@
5656
href: tutorials/tab-title.md
5757
- name: Open tab or pane in same directory
5858
href: tutorials/new-tab-same-directory.md
59+
- name: Set the progress bar
60+
href: tutorials/progress-bar-sequences.md
5961
- name: Custom Terminal gallery
6062
items:
6163
- name: Custom Terminal guide
@@ -74,4 +76,4 @@
7476
href: troubleshooting.md
7577

7678

77-
79+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
title: Set the progress bar in the Windows Terminal
3+
description: In this tutorial, you learn how to use the progress bar sequences in the Windows Terminal.
4+
author: zadjii-msft
5+
ms.author: migrie
6+
ms.date: 08/31/2023
7+
ms.topic: tutorial
8+
#Customer intent: As a developer or IT admin, I want to use the progress bar sequences in the Windows Terminal so that I can see the progress of a long-running command.
9+
---
10+
11+
# Tutorial: Set the progress bar in the Windows Terminal
12+
13+
The Windows Terminal supports the ConEmu "Progress Bar" sequences, also known as "OSC 9;4". These sequences allow a command-line application to display a progress bar in the terminal window. This is useful for long-running commands, such as copying large files or deploying applications.
14+
15+
In the Windows Terminal, the progress bar is displayed in two places:
16+
* In the tab header, as a progress ring
17+
* In the Windows taskbar, in the same manner as a download progress bar.
18+
19+
![An example of what the progress ring it the tab header looks like](https://devblogs.microsoft.com/commandline/wp-content/uploads/sites/33/2021/01/progress-ring.gif)
20+
21+
## Prerequisites
22+
23+
* Windows Terminal v1.6 or later.
24+
* For the taskbar animation, you'll need to make sure "Show animations in Windows" is enabled in "Settings / Ease of Access / Display".
25+
26+
27+
## Progress bar sequence format
28+
29+
To set the progress bar, you need to send the OSC 9;4 sequence to the terminal. This sequence has the following format:
30+
31+
```text
32+
33+
ESC ] 9 ; 4 ; <state> ; <progress> BEL
34+
35+
```
36+
37+
* `ESC` is the escape character, ASCII 27.
38+
* `BEL` is the bell character, ASCII 7.
39+
* `<state>` is one of `0`, `1`, `2`, `3`, or `4`.
40+
* `0` is the default state, and indicates that the progress bar should be hidden. Use this state when the command is complete, to clear out any progress state.
41+
* `1`: set progress value to `<progress>`, in the "default" state.
42+
* `2`: set progress value to `<progress>`, in the "Error" state
43+
* `3`: set the taskbar to the "Indeterminate" state. This is useful for commands that don't have a progress value, but are still running. This state ignores the `<progress>` value.
44+
* `4`: set progress value to `<progress>`, in the "Warning" state
45+
* `<progress>` is a number between 0 and 100, inclusive.
46+
47+
## Examples
48+
49+
### PowerShell
50+
51+
```powershell
52+
# Set the progress bar to 50%
53+
Write-Host -NoNewline ([char]27 + "]9;4;1;50" + [char]7)
54+
```
55+
56+
Or, alternatively, in PowerShell 7:
57+
58+
```powershell
59+
# Set the progress bar to 50%
60+
Write-Host -NoNewline ("`e]9;4;1;50`a")
61+
```
62+
63+
### Bash
64+
65+
```bash
66+
# Set the progress bar to 50%
67+
echo -ne "\033]9;4;1;50\a"
68+
```
69+
70+
### C#
71+
72+
```csharp
73+
// Set the progress bar to 50%
74+
Console.Write("\x1b]9;4;1;50\x07");
75+
```
76+
77+
### Command Prompt
78+
79+
Command Prompt is a little trickier, since it doesn't have great support for escape sequences. You can use the `echo` command to send the escape sequence, but you'll need to use literal ESC and BEL characters in the file. These might be rendered as boxes in the web browser, but they should work in the terminal.
80+
81+
```bat
82+
<NUL set /p =]9;4;1;50
83+
echo Started progress (normal, 50)
84+
```
85+
86+
The above example uses the `NUL` device to write the escape sequence to the console without a newline.
87+
88+
> **Note**:
89+
> Don't see your favorite shell here? If you figure it out, feel free to [to contribute a solution for your preferred shell!](https://github.com/MicrosoftDocs/terminal/compare)

0 commit comments

Comments
 (0)