From e7517419a67438506729409d585b245b77c099ae Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 2 Jul 2024 17:09:16 +0200 Subject: [PATCH] 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 --- src/libmain/progress-bar.cc | 31 +++++++++++++++++++++++-------- src/libmain/progress-bar.hh | 3 +++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc index e4afcd829..f5a22f41b 100644 --- a/src/libmain/progress-bar.cc +++ b/src/libmain/progress-bar.cc @@ -318,6 +318,16 @@ void ProgressBar::update(State & state) 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 & s) { auto nextWakeup = A_LONG_TIME; @@ -331,15 +341,12 @@ std::chrono::milliseconds ProgressBar::draw(State & state, const std::optional::max(); } - if (printMultiline && (state.lastLines >= 1)) { - // FIXME: make sure this works on windows - writeToStderr(fmt("\e[G\e[%dF\e[J", state.lastLines)); - } + eraseProgressDisplay(state); state.lastLines = 0; 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 status = getStatus(state); @@ -401,9 +408,14 @@ std::chrono::milliseconds ProgressBar::draw(State & state, const std::optionalpaused == 0) { + if (isTTY && !printMultiline) { + eraseProgressDisplay(*state); + } Logger::writeToStdout(s); draw(*state, {}); } else { diff --git a/src/libmain/progress-bar.hh b/src/libmain/progress-bar.hh index ad500de6e..8343beff1 100644 --- a/src/libmain/progress-bar.hh +++ b/src/libmain/progress-bar.hh @@ -108,6 +108,9 @@ struct ProgressBar : public Logger void setPrintBuildLogs(bool printBuildLogs) override; void setPrintMultiline(bool printMultiline) override; + +private: + void eraseProgressDisplay(State & state); }; Logger * makeProgressBar();