-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgressBar.h
98 lines (78 loc) · 2.26 KB
/
ProgressBar.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* @file ProgressBar.h
* @brief ProgressBar is a lib, that shows a progress bar in terminal.
*
* Copyright (c) 2020-forever Vlad Rogozin ([email protected])
*
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
*/
#ifndef RED_PROGRESSBAR_H
#define RED_PROGRESSBAR_H
#include <iostream>
#include <string>
#define REDPROGRESSBAR_VERSION "1.1"
namespace Red {
class ProgressBar {
public:
/**
* @brief ProgressBar
*
* Base ctor.
*/
ProgressBar() {}
/**
* @brief Increment
*
* Uses to increment percent variable.
*/
inline void Increment() {
if (Percent <= 100) {
Percent++;
}
}
/**
* @brief Show
*
* Uses to show progress bar
*/
inline void Show() {
std::cout << "\r[\e[42m";
Show_main();
std::cout << std::flush;
}
/**
* @brief Red_Show
*
* Uses to show red progress bar.
*/
inline void Red_Show() {
std::cout << "\r[\e[101m";
Show_main();
std::cout << std::flush;
}
// Base ctor.
~ProgressBar() {}
private:
/**
* @brief Show_main
*
* This function uses to print a progress bar.
*/
inline void Show_main() {
unsigned short int NumOfGreenCubes = Percent / 2;
for (unsigned short int g = 0; g < NumOfGreenCubes; g++) {
std::cout << " ";
}
std::cout << "\e[0m\e[47m";
for (unsigned short int h = 0; h + NumOfGreenCubes < 50; h++) {
std::cout << " ";
}
std::cout << "\e[0m] ";
std::cout << Percent << "% ";
}
// Variables.
unsigned short int Percent = 0;
};
}
#endif // RED_PROGRESSBAR_H