diff --git a/include/progress/bar.hpp b/include/progress/bar.hpp index 16109e5..d629732 100644 --- a/include/progress/bar.hpp +++ b/include/progress/bar.hpp @@ -6,16 +6,16 @@ #include class ProgressBar { - std::string _name{""}; float _progress{0.0}; size_t _bar_width{100}; - std::string _start{"[ "}; - std::string _fill{"■"}; - std::string _lead{"■"}; - std::string _remainder{"-"}; - std::string _end{" ]"}; + std::string _start{"["}; + std::string _fill{"="}; + std::string _lead{">"}; + std::string _remainder{" "}; + std::string _end{"]"}; + std::atomic _completed{false}; + std::atomic _show_percentage{true}; std::mutex _mutex; - std::atomic _completed; void _print_progress() { std::unique_lock lock{_mutex}; @@ -26,8 +26,11 @@ class ProgressBar { else if (i == pos) std::cout << _lead; else std::cout << _remainder; } - std::cout << _end << " " << static_cast(_progress) << "%"; - std::cout << " " << _name << "\r"; + std::cout << _end; + if (_show_percentage) + std::cout << " " << static_cast(_progress) << "%\r"; + else + std::cout << "\r"; std::cout.flush(); if (_completed) std::cout << std::endl; @@ -63,7 +66,11 @@ public: void end_with(const std::string& end) { std::unique_lock lock{_mutex}; _end = end; - } + } + + void show_percentage(bool flag) { + _show_percentage = flag; + } void set_progress(float value) { { diff --git a/test/bar.cpp b/test/bar.cpp index 7a06afe..3672324 100644 --- a/test/bar.cpp +++ b/test/bar.cpp @@ -7,14 +7,14 @@ int main() { // Configure progress bar bar.bar_width(50); bar.start_with("["); - bar.fill_progress_with("="); - bar.lead_progress_with(">"); - bar.fill_remainder_with(" "); - bar.end_with("]"); + bar.fill_progress_with("■"); + bar.lead_progress_with("■"); + bar.fill_remainder_with("-"); + bar.end_with(" ]"); // As configured, the bar will look like this: // - // [=================> ] 70% + // [■■■■■■■■■■■■■■■■■■■■ --------] 70% // //