mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 02:36:16 +02:00
refact: Extract ProgressBar::redraw(newOutput)
This commit is contained in:
parent
9df5236c46
commit
047d9643b5
1 changed files with 18 additions and 13 deletions
|
@ -362,23 +362,28 @@ public:
|
||||||
updateCV.notify_one();
|
updateCV.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::milliseconds draw(State & state)
|
/**
|
||||||
{
|
* Redraw, if the output has changed.
|
||||||
// Call draw() and render if the output has changed.
|
*
|
||||||
|
* Excessive redrawing is noticable on slow terminals, and it interferes
|
||||||
// Excessive redrawing is noticable on slow terminals, and it interferes
|
* with text selection in some terminals, including libvte-based terminal
|
||||||
// with text selection in some terminals, including libvte-based terminal
|
* emulators.
|
||||||
// emulators.
|
*/
|
||||||
|
void redraw(std::string newOutput)
|
||||||
std::optional<std::string> newOutput;
|
|
||||||
auto nextWakeup = draw(state, newOutput);
|
|
||||||
{
|
{
|
||||||
auto state(state_.lock());
|
auto state(state_.lock());
|
||||||
if (newOutput && *newOutput != state->lastOutput) {
|
if (newOutput != state->lastOutput) {
|
||||||
writeToStderr(*newOutput);
|
writeToStderr(newOutput);
|
||||||
state->lastOutput = std::move(*newOutput);
|
state->lastOutput = std::move(newOutput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::chrono::milliseconds draw(State & state)
|
||||||
|
{
|
||||||
|
std::optional<std::string> newOutput;
|
||||||
|
auto nextWakeup = draw(state, newOutput);
|
||||||
|
if (newOutput)
|
||||||
|
redraw(*newOutput);
|
||||||
return nextWakeup;
|
return nextWakeup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue