Logger, ProgressBar: add a way to pause/resume

Add new virtual methods pause and resume to the Logger class, and
implement them in ProgressBar to allow to pause the bar refreshing.
This commit is contained in:
Alexander Bantyev 2023-03-09 18:11:01 +04:00
parent 4dcc0a1b76
commit 85df7e7ea2
No known key found for this signature in database
GPG key ID: 48ABA304F3A30FE9
2 changed files with 16 additions and 0 deletions

View file

@ -72,6 +72,7 @@ private:
uint64_t corruptedPaths = 0, untrustedPaths = 0;
bool active = true;
bool paused = false;
bool haveUpdate = true;
};
@ -120,6 +121,17 @@ public:
updateThread.join();
}
void pause() override {
state_.lock()->paused = true;
writeToStderr("\r\e[K");
}
void resume() override {
state_.lock()->paused = false;
writeToStderr("\r\e[K");
updateCV.notify_one();
}
bool isVerbose() override
{
return printBuildLogs;
@ -338,6 +350,7 @@ public:
{
auto nextWakeup = std::chrono::milliseconds::max();
if (state.paused) return nextWakeup;
state.haveUpdate = false;
if (!state.active) return nextWakeup;

View file

@ -72,6 +72,9 @@ public:
virtual void stop() { };
virtual void pause() { };
virtual void resume() { };
// Whether the logger prints the whole build log
virtual bool isVerbose() { return false; }