mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 06:26:15 +02:00
libmain/progress-bar: try harder to avoid escape sequences if !isTTY
This commit is contained in:
parent
c3e9e3d0c3
commit
950b6401f9
1 changed files with 11 additions and 9 deletions
|
@ -123,14 +123,18 @@ public:
|
|||
}
|
||||
|
||||
void pause() override {
|
||||
state_.lock()->paused = true;
|
||||
writeToStderr("\r\e[K");
|
||||
auto state (state_.lock());
|
||||
state->paused = true;
|
||||
if (state->active)
|
||||
writeToStderr("\r\e[K");
|
||||
}
|
||||
|
||||
void resume() override {
|
||||
state_.lock()->paused = false;
|
||||
writeToStderr("\r\e[K");
|
||||
state_.lock()->haveUpdate = true;
|
||||
auto state (state_.lock());
|
||||
state->paused = false;
|
||||
if (state->active)
|
||||
writeToStderr("\r\e[K");
|
||||
state->haveUpdate = true;
|
||||
updateCV.notify_one();
|
||||
}
|
||||
|
||||
|
@ -162,9 +166,7 @@ public:
|
|||
writeToStderr("\r\e[K" + filterANSIEscapes(s, !isTTY) + ANSI_NORMAL "\n");
|
||||
draw(state);
|
||||
} else {
|
||||
auto s2 = s + ANSI_NORMAL "\n";
|
||||
if (!isTTY) s2 = filterANSIEscapes(s2, true);
|
||||
writeToStderr(s2);
|
||||
writeToStderr(filterANSIEscapes(s, !isTTY) + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -519,7 +521,7 @@ public:
|
|||
std::optional<char> ask(std::string_view msg) override
|
||||
{
|
||||
auto state(state_.lock());
|
||||
if (!state->active || !isatty(STDIN_FILENO)) return {};
|
||||
if (!state->active) return {};
|
||||
std::cerr << fmt("\r\e[K%s ", msg);
|
||||
auto s = trim(readLine(STDIN_FILENO));
|
||||
if (s.size() != 1) return {};
|
||||
|
|
Loading…
Reference in a new issue