1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00

refact: Extract ProgressBar::redraw(newOutput)

This commit is contained in:
Robert Hensing 2024-09-08 01:09:51 +02:00
parent 9df5236c46
commit 047d9643b5

View file

@ -362,23 +362,28 @@ public:
updateCV.notify_one(); updateCV.notify_one();
} }
/**
* Redraw, if the output has changed.
*
* Excessive redrawing is noticable on slow terminals, and it interferes
* with text selection in some terminals, including libvte-based terminal
* emulators.
*/
void redraw(std::string newOutput)
{
auto state(state_.lock());
if (newOutput != state->lastOutput) {
writeToStderr(newOutput);
state->lastOutput = std::move(newOutput);
}
}
std::chrono::milliseconds draw(State & state) std::chrono::milliseconds draw(State & state)
{ {
// Call draw() and render if the output has changed.
// Excessive redrawing is noticable on slow terminals, and it interferes
// with text selection in some terminals, including libvte-based terminal
// emulators.
std::optional<std::string> newOutput; std::optional<std::string> newOutput;
auto nextWakeup = draw(state, newOutput); auto nextWakeup = draw(state, newOutput);
{ if (newOutput)
auto state(state_.lock()); redraw(*newOutput);
if (newOutput && *newOutput != state->lastOutput) {
writeToStderr(*newOutput);
state->lastOutput = std::move(*newOutput);
}
}
return nextWakeup; return nextWakeup;
} }