Hide progress spinner when ProgressBar gets destructed

This commit is contained in:
Daniel Wolf 2019-01-02 14:38:53 +01:00
parent 3189fc8976
commit e87ccc8816
2 changed files with 8 additions and 4 deletions

View File

@ -46,21 +46,25 @@ void ProgressBar::updateLoop() {
if (clearOnDestruction) { if (clearOnDestruction) {
updateText(""); updateText("");
} else { } else {
update(); update(false);
} }
} }
void ProgressBar::update() { void ProgressBar::update(bool showSpinner) {
const int blockCount = 20; const int blockCount = 20;
const string animation = "|/-\\"; const string animation = "|/-\\";
int progressBlockCount = static_cast<int>(currentProgress * blockCount); int progressBlockCount = static_cast<int>(currentProgress * blockCount);
const double epsilon = 0.0001; const double epsilon = 0.0001;
int percent = static_cast<int>(currentProgress * 100 + epsilon); int percent = static_cast<int>(currentProgress * 100 + epsilon);
const string spinner = showSpinner
? string(1, animation[animationIndex++ % animation.size()])
: "";
string text = fmt::format("[{0}{1}] {2:3}% {3}", string text = fmt::format("[{0}{1}] {2:3}% {3}",
string(progressBlockCount, '#'), string(blockCount - progressBlockCount, '-'), string(progressBlockCount, '#'), string(blockCount - progressBlockCount, '-'),
percent, percent,
animation[animationIndex++ % animation.size()]); spinner
);
updateText(text); updateText(text);
} }

View File

@ -22,7 +22,7 @@ public:
private: private:
void updateLoop(); void updateLoop();
void update(); void update(bool showSpinner = true);
void updateText(const std::string& text); void updateText(const std::string& text);
std::future<void> updateLoopFuture; std::future<void> updateLoopFuture;