aboutsummaryrefslogtreecommitdiff
path: root/src/nix/progress-bar.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-08-29 15:13:30 +0200
committerEelco Dolstra <edolstra@gmail.com>2017-08-29 15:13:30 +0200
commitc8235c531355d612d48f633f8a6ace5fcd97f5fe (patch)
treec54d398380ef786e6895b5427774bbd750566b31 /src/nix/progress-bar.cc
parent05d68a6e23127e490193599f75489006830b302c (diff)
nix run: Flush the progress bar before starting the command
Diffstat (limited to 'src/nix/progress-bar.cc')
-rw-r--r--src/nix/progress-bar.cc28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/nix/progress-bar.cc b/src/nix/progress-bar.cc
index 341866679..f48cfa13b 100644
--- a/src/nix/progress-bar.cc
+++ b/src/nix/progress-bar.cc
@@ -95,6 +95,8 @@ private:
uint64_t filesLinked = 0, bytesLinked = 0;
uint64_t corruptedPaths = 0, untrustedPaths = 0;
+
+ bool active = true;
};
Sync<State> state_;
@@ -107,7 +109,14 @@ public:
~ProgressBar()
{
+ stop();
+ }
+
+ void stop()
+ {
auto state(state_.lock());
+ if (!state->active) return;
+ state->active = true;
std::string status = getStatus(*state);
writeToStderr("\r\e[K");
if (status != "")
@@ -268,6 +277,8 @@ public:
void update(State & state)
{
+ if (!state.active) return;
+
std::string line;
std::string status = getStatus(state);
@@ -385,21 +396,16 @@ public:
}
};
-StartProgressBar::StartProgressBar()
+void startProgressBar()
{
- if (isatty(STDERR_FILENO)) {
- prev = logger;
- logger = new ProgressBar();
- }
+ logger = new ProgressBar();
}
-StartProgressBar::~StartProgressBar()
+void stopProgressBar()
{
- if (prev) {
- auto bar = logger;
- logger = prev;
- delete bar;
- }
+ auto progressBar = dynamic_cast<ProgressBar *>(logger);
+ if (progressBar) progressBar->stop();
+
}
}