2019-12-03 09:54:50 -06:00
|
|
|
#pragma once
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
class progress_bar {
|
2019-12-03 10:02:46 -06:00
|
|
|
std::string _name{"Running"};
|
2019-12-03 09:54:50 -06:00
|
|
|
size_t _bar_width{100};
|
|
|
|
|
std::string _start{"|"};
|
|
|
|
|
std::string _end{"|"};
|
|
|
|
|
std::mutex _mutex;
|
|
|
|
|
std::atomic<size_t> _progress{0};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
~progress_bar() {
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void increment(size_t value) {
|
|
|
|
|
std::unique_lock<std::mutex> lock{_mutex};
|
|
|
|
|
_progress = value;
|
2019-12-03 10:02:46 -06:00
|
|
|
std::cout << _name << " [";
|
2019-12-03 09:54:50 -06:00
|
|
|
for (size_t i = 0; i < _bar_width; i++) {
|
2019-12-03 10:02:46 -06:00
|
|
|
if (i < value) std::cout << "#";
|
2019-12-03 09:54:50 -06:00
|
|
|
else if (i == value) std::cout << ">";
|
|
|
|
|
else std::cout << " ";
|
|
|
|
|
}
|
|
|
|
|
std::cout << "] " << int(_progress) << " %\r";
|
|
|
|
|
std::cout.flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t current() {
|
|
|
|
|
return _progress;
|
|
|
|
|
}
|
|
|
|
|
};
|