From 11976c65d0c134472d83b418e35f57a5095bc59c Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Tue, 3 Dec 2019 16:53:17 -0600 Subject: [PATCH] API updates --- include/progress/bar.hpp | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/include/progress/bar.hpp b/include/progress/bar.hpp index 7ac8582..d63e515 100644 --- a/include/progress/bar.hpp +++ b/include/progress/bar.hpp @@ -9,10 +9,11 @@ class ProgressBar { std::string _name{""}; float _progress{0.0}; size_t _bar_width{80}; - std::string _start{"["}; - std::string _step{"■"}; - std::string _head{"■"}; - std::string _end{"]"}; + std::string _start{"[ "}; + std::string _fill{"■"}; + std::string _lead{"■"}; + std::string _negative_space{"-"}; + std::string _end{" ]"}; std::mutex _mutex; void hide_cursor() { @@ -25,7 +26,30 @@ class ProgressBar { public: - explicit ProgressBar(const std::string& name) : _name(name) {} + ProgressBar& start_with(const std::string& start) { + _start = start; + return *this; + } + + ProgressBar& fill_with(const std::string& fill) { + _fill = fill; + return *this; + } + + ProgressBar& lead_with(const std::string& lead) { + _lead = lead; + return *this; + } + + ProgressBar& negative_space(const std::string& negative_space) { + _negative_space = negative_space; + return *this; + } + + ProgressBar& end_with(const std::string& end) { + _end = end; + return *this; + } void increment(float value) { std::unique_lock lock{_mutex}; @@ -34,9 +58,9 @@ public: std::cout << _start; float pos = _progress * static_cast(_bar_width); for (size_t i = 0; i < _bar_width; ++i) { - if (i < pos) std::cout << _step; - else if (i == pos) std::cout << _head; - else std::cout << "-"; + if (i < pos) std::cout << _fill; + else if (i == pos) std::cout << _lead; + else std::cout << _negative_space; } std::cout << _end << " " << static_cast(value) << "%"; std::cout << " " << _name << "\r";