11 : total_(total), barWidth_(barWidth), current_(0), stop_(
false) {
14 thread_ = std::thread(&ProgressBar::run,
this);
21 void update(
int progress) {
23 if (progress > total_) current_ = total_;
28 if (thread_.joinable()) {
35 std::cout << std::flush;
42 std::this_thread::sleep_for(std::chrono::milliseconds(100));
47 float fraction =
static_cast<float>(current_) / total_;
48 int pos =
static_cast<int>(barWidth_ * fraction);
52 for (
int i = 0; i < barWidth_; ++i) {
53 if (i < pos) std::cout <<
"\033[32m=\033[0m";
54 else if (i == pos) std::cout <<
"\033[32m>\033[0m";
55 else std::cout <<
" ";
57 std::cout <<
"] " << int(fraction * 100) <<
" %" << std::flush;
61 std::cout <<
"\033[?25l";
66 std::cout <<
"\033[?25h";
72 std::atomic<int> current_;
73 std::atomic<bool> stop_;
Definition: progress.hpp:8