nix run: Flush the progress bar before starting the command
This commit is contained in:
parent
05d68a6e23
commit
c8235c5313
5 changed files with 28 additions and 19 deletions
|
@ -2,6 +2,7 @@
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
#include "eval.hh"
|
#include "eval.hh"
|
||||||
#include "attr-path.hh"
|
#include "attr-path.hh"
|
||||||
|
#include "progress-bar.hh"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -65,6 +66,8 @@ struct CmdEdit : InstallablesCommand
|
||||||
|
|
||||||
args.push_back(filename);
|
args.push_back(filename);
|
||||||
|
|
||||||
|
stopProgressBar();
|
||||||
|
|
||||||
execvp(editor.c_str(), stringsToCharPtrs(args).data());
|
execvp(editor.c_str(), stringsToCharPtrs(args).data());
|
||||||
|
|
||||||
throw SysError("cannot run editor '%s'", editor);
|
throw SysError("cannot run editor '%s'", editor);
|
||||||
|
|
|
@ -84,7 +84,8 @@ void mainWrapped(int argc, char * * argv)
|
||||||
|
|
||||||
if (!args.command) args.showHelpAndExit();
|
if (!args.command) args.showHelpAndExit();
|
||||||
|
|
||||||
StartProgressBar bar;
|
if (isatty(STDERR_FILENO))
|
||||||
|
startProgressBar();
|
||||||
|
|
||||||
args.command->prepare();
|
args.command->prepare();
|
||||||
args.command->run();
|
args.command->run();
|
||||||
|
|
|
@ -95,6 +95,8 @@ private:
|
||||||
uint64_t filesLinked = 0, bytesLinked = 0;
|
uint64_t filesLinked = 0, bytesLinked = 0;
|
||||||
|
|
||||||
uint64_t corruptedPaths = 0, untrustedPaths = 0;
|
uint64_t corruptedPaths = 0, untrustedPaths = 0;
|
||||||
|
|
||||||
|
bool active = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Sync<State> state_;
|
Sync<State> state_;
|
||||||
|
@ -106,8 +108,15 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
~ProgressBar()
|
~ProgressBar()
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop()
|
||||||
{
|
{
|
||||||
auto state(state_.lock());
|
auto state(state_.lock());
|
||||||
|
if (!state->active) return;
|
||||||
|
state->active = true;
|
||||||
std::string status = getStatus(*state);
|
std::string status = getStatus(*state);
|
||||||
writeToStderr("\r\e[K");
|
writeToStderr("\r\e[K");
|
||||||
if (status != "")
|
if (status != "")
|
||||||
|
@ -268,6 +277,8 @@ public:
|
||||||
|
|
||||||
void update(State & state)
|
void update(State & state)
|
||||||
{
|
{
|
||||||
|
if (!state.active) return;
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
std::string status = getStatus(state);
|
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 progressBar = dynamic_cast<ProgressBar *>(logger);
|
||||||
auto bar = logger;
|
if (progressBar) progressBar->stop();
|
||||||
logger = prev;
|
|
||||||
delete bar;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,8 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
class StartProgressBar
|
void startProgressBar();
|
||||||
{
|
|
||||||
Logger * prev = 0;
|
void stopProgressBar();
|
||||||
public:
|
|
||||||
StartProgressBar();
|
|
||||||
~StartProgressBar();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "local-store.hh"
|
#include "local-store.hh"
|
||||||
#include "finally.hh"
|
#include "finally.hh"
|
||||||
#include "fs-accessor.hh"
|
#include "fs-accessor.hh"
|
||||||
|
#include "progress-bar.hh"
|
||||||
|
|
||||||
#if __linux__
|
#if __linux__
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
@ -107,6 +108,8 @@ struct CmdRun : InstallablesCommand
|
||||||
std::string cmd = *command.begin();
|
std::string cmd = *command.begin();
|
||||||
Strings args = command;
|
Strings args = command;
|
||||||
|
|
||||||
|
stopProgressBar();
|
||||||
|
|
||||||
/* If this is a diverted store (i.e. its "logical" location
|
/* If this is a diverted store (i.e. its "logical" location
|
||||||
(typically /nix/store) differs from its "physical" location
|
(typically /nix/store) differs from its "physical" location
|
||||||
(e.g. /home/eelco/nix/store), then run the command in a
|
(e.g. /home/eelco/nix/store), then run the command in a
|
||||||
|
|
Loading…
Reference in a new issue