forked from OnsenManju/Jist
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConsoleEx.cs
executable file
·46 lines (37 loc) · 1.12 KB
/
ConsoleEx.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
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wolfje.Plugins.Jist {
static class ConsoleEx {
static readonly object __consoleWriteLock = new object();
public static void WriteBar(PercentChangedEventArgs args)
{
StringBuilder output = new StringBuilder();
int fillLen = 0;
char filler = '#', spacer = ' ';
output.Append(" ");
for (int i = 0; i < 10; i++) {
char c = i < args.Label.Length ? args.Label[i] : ' ';
output.Append(c);
}
output.Append(" [");
fillLen = Convert.ToInt32(((decimal)args.Percent / 100) * 60);
for (int i = 0; i < 60; i++) {
output.Append(i <= fillLen ? filler : spacer);
}
output.Append("] ");
output.Append(args.Percent + "%");
lock (__consoleWriteLock) {
Console.Write("\r");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(output.ToString());
Console.ResetColor();
}
}
}
class PercentChangedEventArgs : EventArgs {
public string Label { get; set; }
public decimal Percent { get; set; }
}
}