From 8fbbeb20f517f6bb160c0bc6592e3725f041d2c7 Mon Sep 17 00:00:00 2001 From: Giedrius Jonikas Date: Thu, 7 Nov 2024 18:01:20 +0000 Subject: [PATCH] Optimise multi_progress_bar tty control sequences Instead of sending multiple cursor_up and clear_line sequences, send a single command to move the cursor up multiple lines. This makes the tty::clear_line redundant, because the next update will overwrite the previous lines anyway. --- libdnf5-cli/progressbar/multi_progress_bar.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libdnf5-cli/progressbar/multi_progress_bar.cpp b/libdnf5-cli/progressbar/multi_progress_bar.cpp index c6f07c5e7..8cd9eb499 100644 --- a/libdnf5-cli/progressbar/multi_progress_bar.cpp +++ b/libdnf5-cli/progressbar/multi_progress_bar.cpp @@ -105,9 +105,9 @@ std::ostream & operator<<(std::ostream & stream, MultiProgressBar & mbar) { text_buffer.clear(); if (is_interactive && mbar.num_of_lines_to_clear > 0) { - text_buffer << tty::clear_line; - for (std::size_t i = 1; i < mbar.num_of_lines_to_clear; i++) { - text_buffer << tty::cursor_up << tty::clear_line; + if (mbar.num_of_lines_to_clear > 1) { + // Move the cursor up by the number of lines we want to write over + text_buffer << "\033[" << (mbar.num_of_lines_to_clear - 1) << "A"; } text_buffer << "\r"; } else if (mbar.line_printed) {