Skip to content

Commit

Permalink
When multi_progress_bar finishes print new line automatically
Browse files Browse the repository at this point in the history
The last line of `multi_progress_bar` can look like:
`[2/2] Total           100% |   0.0   B/s |  20.0   B |  00m00s`
or
`http://localhost:43223/api_3/rpmrepo 100% |  72.0 KiB/s | 295.0   B |  00m00s`
I don't think any client will ever want to append to that.

Instead of it needing to be printed by the client the
`multi_progress_bar` automatically ends with a new line.

This new line was missing on some places. For example in output of:
`dnf copr enable rpmsoftwaremanagement/dnf-nightly `
or
`dnf5 rq --repofrompath=test,https://www.not-available-repo.com/ --repo test --setopt=skip_if_unavailable=0`
There were also excessive new lines like in:
`dnf5 remove htop -y &> out`

Closes: #1792
  • Loading branch information
kontura authored and m-blaha committed Nov 1, 2024
1 parent 01d4df8 commit dd79abf
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 10 deletions.
1 change: 0 additions & 1 deletion dnf5/commands/download/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ void DownloadCommand::run() {

std::cout << "Downloading Packages:" << std::endl;
downloader.download();
std::cout << std::endl;
}


Expand Down
2 changes: 0 additions & 2 deletions dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ void Context::Impl::download_and_run(libdnf5::base::Transaction & transaction) {
if (base.get_config().get_downloadonly_option().get_value()) {
return;
}
print_info("");

if (should_store_offline) {
store_offline(transaction);
Expand Down Expand Up @@ -493,7 +492,6 @@ void Context::Impl::download_and_run(libdnf5::base::Transaction & transaction) {
}

auto result = transaction.run();
print_info("");
if (result != libdnf5::base::Transaction::TransactionRunResult::SUCCESS) {
print_error(libdnf5::utils::sformat(
_("Transaction failed: {}"), libdnf5::base::Transaction::transaction_result_to_string(result)));
Expand Down
1 change: 0 additions & 1 deletion dnf5/download_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ int DownloadCallbacks::mirror_failure(void * user_cb_data, const char * msg, con
void DownloadCallbacks::reset_progress_bar() {
multi_progress_bar.reset();
if (printed) {
std::cerr << std::endl;
printed = false;
}
}
Expand Down
1 change: 0 additions & 1 deletion dnf5daemon-client/callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ void DownloadCB::print() {
void DownloadCB::reset_progress_bar() {
multi_progress_bar.reset();
if (printed) {
std::cerr << std::endl;
printed = false;
}
}
Expand Down
8 changes: 3 additions & 5 deletions libdnf5-cli/progressbar/multi_progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,8 @@ std::ostream & operator<<(std::ostream & stream, MultiProgressBar & mbar) {
}
bar->set_number(numbers.back());
numbers.pop_back();
if (mbar.line_printed) {
stream << std::endl;
}
stream << *bar;
mbar.line_printed = true;
stream << std::endl;
mbar.bars_done.push_back(bar);
// TODO(dmach): use iterator
mbar.bars_todo.erase(mbar.bars_todo.begin() + static_cast<int>(i));
Expand Down Expand Up @@ -200,7 +197,8 @@ std::ostream & operator<<(std::ostream & stream, MultiProgressBar & mbar) {
}

stream << mbar.total;
mbar.num_of_lines_to_clear += 2;
stream << std::endl;
mbar.num_of_lines_to_clear += 3;
}

return stream;
Expand Down

0 comments on commit dd79abf

Please sign in to comment.