-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogressBar.h
More file actions
38 lines (30 loc) · 829 Bytes
/
progressBar.h
File metadata and controls
38 lines (30 loc) · 829 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
33
34
35
36
37
38
#pragma once
// Copyright (c) 2021-present Stefan Mada.
// Distributed under the MIT license that can be found in the LICENSE file.
// Version: January 30, 2023
#include <iostream>
struct ProgressBar {
ProgressBar(int lowerBound, int upperBound) {
maxProgress = upperBound - lowerBound;
update(0);
}
void update(int currProgress) {
progress = currProgress;
std::cerr << "[";
int pos = ((float)progress / maxProgress) * barWidth;
for (int i = 0; i < barWidth; ++i) {
if (i < pos)
std::cerr << "=";
else if (i == pos)
std::cerr << ">";
else
std::cerr << " ";
}
std::cerr << "] " << int(((float)progress / maxProgress) * 100.0) << " %\r";
std::cerr.flush();
}
private:
int progress = 0;
int maxProgress;
const int barWidth = 70;
};