mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
When the max_progress value is >1.67772e+07, the progress_ which is float, is not chanegd when tick() is called as +1 is outside of the precission for a float value. The bar stays at value of 1.67772e+07 and 67%. In this fix I introduced tics_ varialbe of size_t which is increased with every tick. And the progress_ is calcualted as a ratio of tick_/max_progress. The breaking and required change is the change of set_progress(float) to set_progress(size_t), so it modifies directly the tics_ value.
31 lines
686 B
C++
31 lines
686 B
C++
#include <chrono>
|
|
#include <indicators/block_progress_bar.hpp>
|
|
#include <indicators/cursor_control.hpp>
|
|
#include <thread>
|
|
|
|
int main() {
|
|
|
|
// Hide cursor
|
|
indicators::show_console_cursor(false);
|
|
|
|
indicators::BlockProgressBar bar{
|
|
indicators::option::BarWidth{80},
|
|
indicators::option::FontStyles{
|
|
std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};
|
|
|
|
// Update bar state
|
|
auto progress = 0.0f;
|
|
while (true) {
|
|
bar.set_progress(progress);
|
|
progress += 1;
|
|
if (bar.is_completed())
|
|
break;
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
|
}
|
|
|
|
// Show cursor
|
|
indicators::show_console_cursor(true);
|
|
|
|
return 0;
|
|
}
|