1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

progress-bar: Make pause/resume nestable

This commit is contained in:
Robert Hensing 2025-03-04 18:30:34 +01:00
parent a5cf291dde
commit 49d8ee5359

View file

@ -73,8 +73,13 @@ private:
uint64_t corruptedPaths = 0, untrustedPaths = 0;
bool active = true;
bool paused = false;
size_t suspensions = 0;
bool haveUpdate = true;
bool isPaused() const
{
return suspensions > 0;
}
};
/** Helps avoid unnecessary redraws, see `redraw()` */
@ -130,19 +135,31 @@ public:
void pause() override {
auto state (state_.lock());
state->paused = true;
state->suspensions++;
if (state->suspensions > 1) {
// already paused
return;
}
if (state->active)
writeToStderr("\r\e[K");
}
void resume() override {
auto state (state_.lock());
state->paused = false;
if (state->suspensions == 0) {
log(lvlError, "nix::ProgressBar: resume() called without a matching preceding pause(). This is a bug.");
return;
} else {
state->suspensions--;
}
if (state->suspensions == 0) {
if (state->active)
writeToStderr("\r\e[K");
state->haveUpdate = true;
updateCV.notify_one();
}
}
bool isVerbose() override
{
@ -383,7 +400,7 @@ public:
auto nextWakeup = std::chrono::milliseconds::max();
state.haveUpdate = false;
if (state.paused || !state.active) return nextWakeup;
if (state.isPaused() || !state.active) return nextWakeup;
std::string line;