Skip to content

Commit

Permalink
Optimise multi_progress_bar tty control sequences
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Giedriusj1 committed Nov 8, 2024
1 parent 6ad9ec4 commit d216705
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libdnf5-cli/progressbar/multi_progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d216705

Please sign in to comment.