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:
parent
a5cf291dde
commit
49d8ee5359
1 changed files with 25 additions and 8 deletions
|
@ -73,8 +73,13 @@ private:
|
||||||
uint64_t corruptedPaths = 0, untrustedPaths = 0;
|
uint64_t corruptedPaths = 0, untrustedPaths = 0;
|
||||||
|
|
||||||
bool active = true;
|
bool active = true;
|
||||||
bool paused = false;
|
size_t suspensions = 0;
|
||||||
bool haveUpdate = true;
|
bool haveUpdate = true;
|
||||||
|
|
||||||
|
bool isPaused() const
|
||||||
|
{
|
||||||
|
return suspensions > 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Helps avoid unnecessary redraws, see `redraw()` */
|
/** Helps avoid unnecessary redraws, see `redraw()` */
|
||||||
|
@ -130,18 +135,30 @@ public:
|
||||||
|
|
||||||
void pause() override {
|
void pause() override {
|
||||||
auto state (state_.lock());
|
auto state (state_.lock());
|
||||||
state->paused = true;
|
state->suspensions++;
|
||||||
|
if (state->suspensions > 1) {
|
||||||
|
// already paused
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (state->active)
|
if (state->active)
|
||||||
writeToStderr("\r\e[K");
|
writeToStderr("\r\e[K");
|
||||||
}
|
}
|
||||||
|
|
||||||
void resume() override {
|
void resume() override {
|
||||||
auto state (state_.lock());
|
auto state (state_.lock());
|
||||||
state->paused = false;
|
if (state->suspensions == 0) {
|
||||||
if (state->active)
|
log(lvlError, "nix::ProgressBar: resume() called without a matching preceding pause(). This is a bug.");
|
||||||
writeToStderr("\r\e[K");
|
return;
|
||||||
state->haveUpdate = true;
|
} else {
|
||||||
updateCV.notify_one();
|
state->suspensions--;
|
||||||
|
}
|
||||||
|
if (state->suspensions == 0) {
|
||||||
|
if (state->active)
|
||||||
|
writeToStderr("\r\e[K");
|
||||||
|
state->haveUpdate = true;
|
||||||
|
updateCV.notify_one();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isVerbose() override
|
bool isVerbose() override
|
||||||
|
@ -383,7 +400,7 @@ public:
|
||||||
auto nextWakeup = std::chrono::milliseconds::max();
|
auto nextWakeup = std::chrono::milliseconds::max();
|
||||||
|
|
||||||
state.haveUpdate = false;
|
state.haveUpdate = false;
|
||||||
if (state.paused || !state.active) return nextWakeup;
|
if (state.isPaused() || !state.active) return nextWakeup;
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue