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();
|
||||
}
|
||||
|
||||
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;
|
||||
auto nextWakeup = draw(state, newOutput);
|
||||
/**
|
||||
* 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 && *newOutput != state->lastOutput) {
|
||||
writeToStderr(*newOutput);
|
||||
state->lastOutput = std::move(*newOutput);
|
||||
if (newOutput != state->lastOutput) {
|
||||
writeToStderr(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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue