-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress_bar.h
More file actions
32 lines (28 loc) · 847 Bytes
/
progress_bar.h
File metadata and controls
32 lines (28 loc) · 847 Bytes
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
#include <iostream>
class ProgressBar {
public:
ProgressBar(size_t total, size_t ping): ping_(ping), total_(total) {
}
void UpgradeProgress(size_t cur_value) {
if (cur_value % ping_ != 0) {
return;
}
float progress = (cur_value + 0.0) / (total_ + 0.0);
{
int barWidth = 70;
std::cout << "[";
int pos = barWidth * progress;
for (int i = 0; i < barWidth; ++i) {
if (i < pos) std::cout << "=";
else if (i == pos) std::cout << ">";
else std::cout << " ";
}
std::cout << "] " << int(progress * 100.0) << " %\r";
std::cout.flush();
}
std::cout << std::endl;
}
private:
size_t total_;
size_t ping_;
};