libmain: better fix for #424, #425

not printing activities at all when no progress information is available
hides *all* progress information from e.g. flake show. this is not ideal
and needs to be fixed, but the fix *still* has problems with flake show:
in multiline mode we will overwrite all useful flake show output as soon
as the progress bar is redrawn. flake show output is also mangled in any
number of other situations (like -v being set), so we should probably be
not too worried about it and fix progress reporting properly another day

Change-Id: I6d39d670e261bbae00560b6a8e15dec8e16b35c4
This commit is contained in:
eldritch horrors 2024-07-02 17:09:16 +02:00
parent 24852355d8
commit e7517419a6
2 changed files with 26 additions and 8 deletions

View file

@ -318,6 +318,16 @@ void ProgressBar::update(State & state)
updateCV.notify_one(); updateCV.notify_one();
} }
void ProgressBar::eraseProgressDisplay(State & state)
{
if (printMultiline && (state.lastLines >= 1)) {
// FIXME: make sure this works on windows
writeToStderr(fmt("\e[G\e[%dF\e[J", state.lastLines));
} else {
writeToStderr("\r\e[K");
}
}
std::chrono::milliseconds ProgressBar::draw(State & state, const std::optional<std::string_view> & s) std::chrono::milliseconds ProgressBar::draw(State & state, const std::optional<std::string_view> & s)
{ {
auto nextWakeup = A_LONG_TIME; auto nextWakeup = A_LONG_TIME;
@ -331,15 +341,12 @@ std::chrono::milliseconds ProgressBar::draw(State & state, const std::optional<s
width = std::numeric_limits<decltype(width)>::max(); width = std::numeric_limits<decltype(width)>::max();
} }
if (printMultiline && (state.lastLines >= 1)) { eraseProgressDisplay(state);
// FIXME: make sure this works on windows
writeToStderr(fmt("\e[G\e[%dF\e[J", state.lastLines));
}
state.lastLines = 0; state.lastLines = 0;
if (s != std::nullopt) if (s != std::nullopt)
writeToStderr("\r\e[K" + filterANSIEscapes(s.value(), !isTTY) + ANSI_NORMAL "\n"); writeToStderr(filterANSIEscapes(s.value(), !isTTY) + ANSI_NORMAL "\n");
std::string line; std::string line;
std::string status = getStatus(state); std::string status = getStatus(state);
@ -401,9 +408,14 @@ std::chrono::milliseconds ProgressBar::draw(State & state, const std::optional<s
if (printMultiline && moreActivities) if (printMultiline && moreActivities)
writeToStderr(fmt("And %d more...", moreActivities)); writeToStderr(fmt("And %d more...", moreActivities));
if (!printMultiline && !line.empty()) { if (!printMultiline) {
line += " " + activity_line; if (!line.empty()) {
writeToStderr("\r" + filterANSIEscapes(line, false, width) + ANSI_NORMAL + "\e[K"); line += " ";
}
line += activity_line;
if (!line.empty()) {
writeToStderr(filterANSIEscapes(line, false, width) + ANSI_NORMAL);
}
} }
return nextWakeup; return nextWakeup;
@ -531,6 +543,9 @@ void ProgressBar::writeToStdout(std::string_view s)
{ {
auto state(state_.lock()); auto state(state_.lock());
if (state->paused == 0) { if (state->paused == 0) {
if (isTTY && !printMultiline) {
eraseProgressDisplay(*state);
}
Logger::writeToStdout(s); Logger::writeToStdout(s);
draw(*state, {}); draw(*state, {});
} else { } else {

View file

@ -108,6 +108,9 @@ struct ProgressBar : public Logger
void setPrintBuildLogs(bool printBuildLogs) override; void setPrintBuildLogs(bool printBuildLogs) override;
void setPrintMultiline(bool printMultiline) override; void setPrintMultiline(bool printMultiline) override;
private:
void eraseProgressDisplay(State & state);
}; };
Logger * makeProgressBar(); Logger * makeProgressBar();