From 4715d557ef1c0dd306cde585820a2a00accd51d6 Mon Sep 17 00:00:00 2001 From: Alois Wohlschlager Date: Sat, 7 Sep 2024 10:37:12 +0200 Subject: [PATCH] libmain/progress-bar: erase all lines of the multi-line format When the multi-line log format is enabled, the progress bar usually occupies multiple lines on the screen. When stopping the progress bar, only the last line was wiped, leaving all others visible on the screen. Erase all lines belonging to the progress bar to prevent these leftovers. Asking the user for input is theoretically affected by a similar issue, but this is not observed in practice since the only place where the user is asked (whether configuration options coming from flakes should be accepted) does not actually have multiple lines on the progress bar. However, there is no real reason to not fix this either, so let's do it anyway. Change-Id: Iaa5a701874fca32e6f06d85912835d86b8fa7a16 --- src/libmain/progress-bar.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc index cdb15d8c7..68349ad26 100644 --- a/src/libmain/progress-bar.cc +++ b/src/libmain/progress-bar.cc @@ -92,7 +92,7 @@ void ProgressBar::resume() nextWakeup = draw(*state, {}); state.wait_for(quitCV, std::chrono::milliseconds(50)); } - writeLogsToStderr("\r\e[K"); + eraseProgressDisplay(*state); }); } @@ -558,7 +558,8 @@ std::optional ProgressBar::ask(std::string_view msg) { auto state(state_.lock()); if (state->paused > 0 || !isatty(STDIN_FILENO)) return {}; - std::cerr << fmt("\r\e[K%s ", msg); + eraseProgressDisplay(*state); + std::cerr << msg; auto s = trim(readLine(STDIN_FILENO)); if (s.size() != 1) return {}; draw(*state, {});