diff --git a/include/progressbar.hpp b/include/progressbar.hpp index 2ac1975..e476491 100644 --- a/include/progressbar.hpp +++ b/include/progressbar.hpp @@ -5,31 +5,29 @@ #include #include -template -class progress_bar { +class ProgressBar { std::string _name{"Running"}; size_t _bar_width{80}; std::string _start{"|"}; std::string _end{"|"}; std::mutex _mutex; - T _progress{T()}; + float _progress{0.0}; public: - ~progress_bar() { - std::cout << std::endl; - } - - void increment(T value) { - std::unique_lock lock{_mutex}; + explicit ProgressBar(const std::string& name) : _name(name) {} + + void increment(float value) { + std::unique_lock lock{_mutex}; _progress = value / 100.0; std::cout << _name << " ["; - T pos = _progress * static_cast(_bar_width); + float pos = _progress * static_cast(_bar_width); for (size_t i = 0; i < _bar_width; ++i) { if (i < pos) std::cout << '#'; else if (i == pos) std::cout << ">"; else std::cout << " "; } - std::cout << "] " << static_cast(value) << " %\r" << std::flush; + std::cout << "] " << static_cast(value) << "%\r"; + std::cout.flush(); } };