indicator progress bar can hit 100 only once.
leimao opened this issue · comments
Indicator progress bar can hit 100 only once, otherwise progress bar will replicate.
#include "indicators.hpp"
#include <thread>
#include <chrono>
int main() {
// Hide cursor
indicators::show_console_cursor(false);
indicators::ProgressBar bar{
indicators::option::BarWidth{50},
indicators::option::Start{" ["},
indicators::option::Fill{"█"},
indicators::option::Lead{"█"},
indicators::option::Remainder{"-"},
indicators::option::End{"]"},
indicators::option::PrefixText{"Training Gaze Network"},
// indicators::option::ForegroundColor{indicators::Color::yellow},
indicators::option::ShowElapsedTime{true},
indicators::option::ShowRemainingTime{true},
indicators::option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}
};
for (int i = 0; i < 10; i ++)
{
bar.set_progress(100);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
// Show cursor
indicators::show_console_cursor(true);
return 0;
}
root@b2a7803832aa:/mnt# g++ indicator_test.cpp indicators.hpp -o indicator_test
root@b2a7803832aa:/mnt# ./indicator_test
Training Gaze Network [██████████████████████████████████████████████████] [00m:00s<00m:00s]
Training Gaze Network [██████████████████████████████████████████████████] [00m:00s<00m:00s]
Training Gaze Network [██████████████████████████████████████████████████] [00m:00s<00m:00s]
Training Gaze Network [██████████████████████████████████████████████████] [00m:00s<00m:00s]
Training Gaze Network [██████████████████████████████████████████████████] [00m:00s<00m:00s]
Training Gaze Network [██████████████████████████████████████████████████] [00m:00s<00m:00s]
Training Gaze Network [██████████████████████████████████████████████████] [00m:00s<00m:00s]
Training Gaze Network [██████████████████████████████████████████████████] [00m:00s<00m:00s]
Training Gaze Network [██████████████████████████████████████████████████] [00m:00s<00m:00s]
Training Gaze Network [██████████████████████████████████████████████████] [00m:00s<00m:00s]
It seems that I can use is_completed
.
Yes, the pattern of using tick()
or set_progress()
, especially in a multi-threaded fashion, assumes you will be checking with is_completed()
before updating the amount of progress.