-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAnsi.cs
43 lines (35 loc) · 993 Bytes
/
Ansi.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using Spectre.Console;
namespace SteamTokenDumper;
static class Ansi
{
// https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC
// https://learn.microsoft.com/en-us/windows/terminal/tutorials/progress-bar-sequences
internal enum ProgressState
{
Hidden = 0,
Default = 1,
Error = 2,
Indeterminate = 3,
Warning = 4,
}
const string ESC = "\u001b";
const string BEL = "\u0007";
public static void Progress(ProgressTask task)
{
Progress(ProgressState.Default, (byte)task.Percentage);
}
public static void Progress(ProgressState state, byte progress = 0)
{
if (OperatingSystem.IsLinux())
{
return;
}
var caps = AnsiConsole.Profile.Capabilities;
if (!caps.Interactive || !caps.Ansi || caps.Legacy)
{
return;
}
Console.Write($"{ESC}]9;4;{(byte)state};{progress}{BEL}");
}
}