diff --git a/README.md b/README.md index 91c33f6..0bb5d74 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ make ## Table of Contents * [Progress Bar](#progress-bar) +* [Indeterminate Progress Bar](#indeterminate-progress-bar) * [Block Progress Bar](#block-progress-bar) * [Multi Progress](#multiprogress) * [Dynamic Progress](#dynamicprogress) @@ -212,6 +213,61 @@ int main() { } ``` +## Indeterminate Progress Bar + +You might have a use-case for a progress bar where the maximum amount of progress is unknown, e.g., you're downloading from a remote server that isn't advertising the total bytes. + +Use an `indicators::IndeterminateProgressBar` for such cases. An `IndeterminateProgressBar` is similar to a regular progress bar except the total amount to progress towards is unknown. Ticking on this progress bar will happily run forever. + +When you know progress is complete, simply call `bar.mark_as_completed()`. + +

+ +

+ +```cpp +#include +#include +#include +#include +#include + +int main() { + indicators::IndeterminateProgressBar bar{ + indicators::option::BarWidth{40}, + indicators::option::Start{"["}, + indicators::option::Fill{"ยท"}, + indicators::option::Lead{"<==>"}, + indicators::option::End{"]"}, + indicators::option::PostfixText{"Checking for Updates"}, + indicators::option::ForegroundColor{indicators::Color::yellow}, + indicators::option::FontStyles{ + std::vector{indicators::FontStyle::bold}} + }; + + indicators::show_console_cursor(false); + + auto job = [&bar]() { + std::this_thread::sleep_for(std::chrono::milliseconds(10000)); + bar.mark_as_completed(); + std::cout << termcolor::bold << termcolor::green + << "System is up to date!\n" << termcolor::reset; + }; + std::thread job_completion_thread(job); + + // Update bar state + while (!bar.is_completed()) { + bar.tick(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + + job_completion_thread.join(); + + indicators::show_console_cursor(true); + return 0; +} +``` + ## Block Progress Bar Are you in need of a smooth block progress bar using [unicode block elements](https://en.wikipedia.org/wiki/Block_Elements)? Use `BlockProgressBar` instead of `ProgressBar`. Thanks to [this blog post](https://mike42.me/blog/2018-06-make-better-cli-progress-bars-with-unicode-block-characters) for making `BlockProgressBar` an easy addition to the library.