From 85df7e7ea24b9f7badbcec06a54e144a0cf1baf5 Mon Sep 17 00:00:00 2001 From: Alexander Bantyev Date: Thu, 9 Mar 2023 18:11:01 +0400 Subject: [PATCH] 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. --- src/libmain/progress-bar.cc | 13 +++++++++++++ src/libutil/logging.hh | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc index 024259584..882deb169 100644 --- a/src/libmain/progress-bar.cc +++ b/src/libmain/progress-bar.cc @@ -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; diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index 59a707eef..1a37aea9e 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -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; }