From e87ccc88167895dba6805ea2b031be771eceecfd Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Wed, 2 Jan 2019 14:38:53 +0100 Subject: [PATCH] Hide progress spinner when ProgressBar gets destructed --- rhubarb/src/tools/ProgressBar.cpp | 10 +++++++--- rhubarb/src/tools/ProgressBar.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rhubarb/src/tools/ProgressBar.cpp b/rhubarb/src/tools/ProgressBar.cpp index 5ba39d2..4f913d7 100644 --- a/rhubarb/src/tools/ProgressBar.cpp +++ b/rhubarb/src/tools/ProgressBar.cpp @@ -46,21 +46,25 @@ void ProgressBar::updateLoop() { if (clearOnDestruction) { updateText(""); } else { - update(); + update(false); } } -void ProgressBar::update() { +void ProgressBar::update(bool showSpinner) { const int blockCount = 20; const string animation = "|/-\\"; int progressBlockCount = static_cast(currentProgress * blockCount); const double epsilon = 0.0001; int percent = static_cast(currentProgress * 100 + epsilon); + const string spinner = showSpinner + ? string(1, animation[animationIndex++ % animation.size()]) + : ""; string text = fmt::format("[{0}{1}] {2:3}% {3}", string(progressBlockCount, '#'), string(blockCount - progressBlockCount, '-'), percent, - animation[animationIndex++ % animation.size()]); + spinner + ); updateText(text); } diff --git a/rhubarb/src/tools/ProgressBar.h b/rhubarb/src/tools/ProgressBar.h index 2dd5f7a..347b330 100644 --- a/rhubarb/src/tools/ProgressBar.h +++ b/rhubarb/src/tools/ProgressBar.h @@ -22,7 +22,7 @@ public: private: void updateLoop(); - void update(); + void update(bool showSpinner = true); void updateText(const std::string& text); std::future updateLoopFuture;