-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPB.cs
48 lines (43 loc) · 1.41 KB
/
PB.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
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Droid_NG___2._0
{
class PB
{
private static string Repeat(string str, int times)
{
return string.Concat(Enumerable.Repeat(str, times));
}
// Progress Bar
public static void ProgressBar(int progress, int total, int chunks = 30, ConsoleColor completeColour = ConsoleColor.Green, ConsoleColor remainingColour = ConsoleColor.Gray, string symbol = "■", bool showPercent = true)
{
//Draw Blank Progress Bar
Console.CursorLeft = 0;
Console.Write(" [");
Console.CursorLeft = chunks + 3;
Console.Write("]");
Console.CursorLeft = 3;
float chunk = (float)chunks / total;
// Chunk Calculations
double completeRaw = Math.Ceiling((double)chunk * progress);
int complete = (int)Math.Ceiling((double)chunk * progress);
int remaining = chunks - complete;
// Draw Progress
Console.ForegroundColor = completeColour;
Console.Write(Repeat(symbol, complete));
Console.ForegroundColor = remainingColour;
Console.Write(Repeat(symbol, remaining));
// Show Percent
Console.CursorLeft = chunks + 4;
Console.ResetColor();
if (showPercent)
{
int percent = (int)((float)progress / (float)total * 100);
Console.Write($" {Repeat(" ", 3 - percent.ToString().Length)}{percent} %");
}
}
}
}