| 1 | package ansi |
| 2 | |
| 3 | import "strconv" |
| 4 | |
| 5 | // ResetProgressBar is a sequence that resets the progress bar to its default |
| 6 | // state (hidden). |
| 7 | // |
| 8 | // OSC 9 ; 4 ; 0 BEL |
| 9 | // |
| 10 | // See: https://learn.microsoft.com/en-us/windows/terminal/tutorials/progress-bar-sequences |
| 11 | const ResetProgressBar = "\x1b]9;4;0\x07" |
| 12 | |
| 13 | // SetProgressBar returns a sequence for setting the progress bar to a specific |
| 14 | // percentage (0-100) in the "default" state. |
| 15 | // |
| 16 | // OSC 9 ; 4 ; 1 Percentage BEL |
| 17 | // |
| 18 | // See: https://learn.microsoft.com/en-us/windows/terminal/tutorials/progress-bar-sequences |
| 19 | func SetProgressBar(percentage int) string { |
| 20 | return "\x1b]9;4;1;" + strconv.Itoa(min(max(0, percentage), 100)) + "\x07" |
| 21 | } |
| 22 | |
| 23 | // SetErrorProgressBar returns a sequence for setting the progress bar to a |
| 24 | // specific percentage (0-100) in the "Error" state.. |
| 25 | // |
| 26 | // OSC 9 ; 4 ; 2 Percentage BEL |
| 27 | // |
| 28 | // See: https://learn.microsoft.com/en-us/windows/terminal/tutorials/progress-bar-sequences |
| 29 | func SetErrorProgressBar(percentage int) string { |
| 30 | return "\x1b]9;4;2;" + strconv.Itoa(min(max(0, percentage), 100)) + "\x07" |
| 31 | } |
| 32 | |
| 33 | // SetIndeterminateProgressBar is a sequence that sets the progress bar to the |
| 34 | // indeterminate state. |
| 35 | // |
| 36 | // OSC 9 ; 4 ; 3 BEL |
| 37 | // |
| 38 | // See: https://learn.microsoft.com/en-us/windows/terminal/tutorials/progress-bar-sequences |
| 39 | const SetIndeterminateProgressBar = "\x1b]9;4;3\x07" |
| 40 | |
| 41 | // SetWarningProgressBar is a sequence that sets the progress bar to the |
| 42 | // "Warning" state. |
| 43 | // |
| 44 | // OSC 9 ; 4 ; 4 Percentage BEL |
| 45 | // |
| 46 | // See: https://learn.microsoft.com/en-us/windows/terminal/tutorials/progress-bar-sequences |
| 47 | func SetWarningProgressBar(percentage int) string { |
| 48 | return "\x1b]9;4;4;" + strconv.Itoa(min(max(0, percentage), 100)) + "\x07" |
| 49 | } |