From b3163df9f7b46330208f5e1c70b8787d8466b6a7 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Fri, 2 Aug 2024 13:24:17 +0200 Subject: [PATCH] cli: Method to drop the last progress bar message Useful to create "temporary" messages, will be used to reduce the "Running scriptlet" / "Stop scriptlet" rpm transaction noise. --- include/libdnf5-cli/progressbar/progress_bar.hpp | 2 ++ libdnf5-cli/progressbar/progress_bar.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/include/libdnf5-cli/progressbar/progress_bar.hpp b/include/libdnf5-cli/progressbar/progress_bar.hpp index d352f4251..940f156f9 100644 --- a/include/libdnf5-cli/progressbar/progress_bar.hpp +++ b/include/libdnf5-cli/progressbar/progress_bar.hpp @@ -95,6 +95,8 @@ class LIBDNF_CLI_API ProgressBar { // messages void add_message(MessageType type, const std::string & message) { messages.emplace_back(type, message); } + /// remove the last message + void pop_message(); const std::vector & get_messages() const noexcept { return messages; } // auto-finish feature; turn off if you want to handle state manually diff --git a/libdnf5-cli/progressbar/progress_bar.cpp b/libdnf5-cli/progressbar/progress_bar.cpp index 73002a2de..99cb44d1b 100644 --- a/libdnf5-cli/progressbar/progress_bar.cpp +++ b/libdnf5-cli/progressbar/progress_bar.cpp @@ -159,6 +159,13 @@ void ProgressBar::set_total_ticks(int64_t value) { } +void ProgressBar::pop_message() { + if (!messages.empty()) { + messages.pop_back(); + } +} + + std::ostream & operator<<(std::ostream & os, ProgressBar & bar) { bar.to_stream(os); return os;