aboutsummaryrefslogtreecommitdiff
path: root/src/libmain/progress-bar.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-07-02 17:09:16 +0200
committereldritch horrors <pennae@lix.systems>2024-07-02 17:16:30 +0200
commite7517419a67438506729409d585b245b77c099ae (patch)
tree4c712c2f688af439875de9ba0d0c8c34f773a3a4 /src/libmain/progress-bar.cc
parent24852355d8975dcc786ddc4d5853043a52e4c78c (diff)
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
Diffstat (limited to 'src/libmain/progress-bar.cc')
-rw-r--r--src/libmain/progress-bar.cc31
1 files changed, 23 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<std::string_view> & s)
{
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();
}
- 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::optional<s
if (printMultiline && moreActivities)
writeToStderr(fmt("And %d more...", moreActivities));
- if (!printMultiline && !line.empty()) {
- line += " " + activity_line;
- writeToStderr("\r" + filterANSIEscapes(line, false, width) + ANSI_NORMAL + "\e[K");
+ if (!printMultiline) {
+ if (!line.empty()) {
+ line += " ";
+ }
+ line += activity_line;
+ if (!line.empty()) {
+ writeToStderr(filterANSIEscapes(line, false, width) + ANSI_NORMAL);
+ }
}
return nextWakeup;
@@ -531,6 +543,9 @@ void ProgressBar::writeToStdout(std::string_view s)
{
auto state(state_.lock());
if (state->paused == 0) {
+ if (isTTY && !printMultiline) {
+ eraseProgressDisplay(*state);
+ }
Logger::writeToStdout(s);
draw(*state, {});
} else {