Activity Indicators for Modern C++
include/indicators. single_include/indicators.To introduce a progress bar in your application, include indicators/progress_bar.hpp and create a ProgressBar object. Here's the general structure of a progress bar:
{prefix} {start} {fill} {lead} {remaining} {end} {percentage} [{elapsed}<{remaining}] {postfix}
^^^^^^^^^^^^^ Bar Width ^^^^^^^^^^^^^^^ The amount of progress in ProgressBar is maintained as a size_t in range [0, 100]. When progress reaches 100, the progression is complete.
From application-level code, there are two ways in which you can update this progress:
bar.tick()You can update the progress bar using bar.tick() which increments progress by exactly 1%.
…The above code will print a progress bar that goes from 0 to 100% at the rate of 1% every 100 ms.
bar.set_progress(value)If you'd rather control progress of the bar in discrete steps, consider using bar.set_progress(value). Example:
…All progress bars and spinners in indicators support showing time elapsed and time remaining. Inspired by python's tqdm module, the format of this meter is [{elapsed}<{remaining}]:
…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().
…Are you in need of a smooth block progress bar using unicode block elements? Use BlockProgressBar instead of ProgressBar. Thanks to this blog post for making BlockProgressBar an easy addition to the library.
…indicators supports management of multiple progress bars with the MultiProgress class template.
template <typename Indicator, size_t count> class MultiProgress is a class template that holds references to multiple progress bars and provides a safe interface to update the state of each bar. MultiProgress works with both ProgressBar and BlockProgressBar classes.
Use this class if you know the number of progress bars to manage at compile time.
Below is an example MultiProgress object that manages three ProgressBar objects.
…DynamicProgress is a container class, similar to MultiProgress, for managing multiple progress bars. As the name suggests, with DynamicProgress, you can dynamically add new progress bars.
To add new progress bars, call bars.push_back(new_bar). This call will return the index of the appended bar. You can then refer to this bar with the indexing operator, e.g., bars[4].set_progress(55).
Use this class if you don't know the number of progress bars at compile time.
Below is an example DynamicProgress object that manages six ProgressBar objects. Three of these bars are added dynamically.
…In the above code, notice the option bars.set_option(option::HideBarWhenComplete{true});. Yes, you can hide progress bars as and when they complete by setting this option to true. If you do so, the above example will look like this:
To introduce a progress spinner in your application, include indicators/progress_spinner.hpp and create a ProgressSpinner object. Here's the general structure of a progress spinner:
{prefix} {spinner} {percentage} [{elapsed}<{remaining}] {postfix}ProgressSpinner has a vector of strings: spinner_states. At each update, the spinner will pick the next string from this sequence to print to the console. The spinner state can be updated similarly to ProgressBars: Using either tick() or set_progress(value).
…indicators allows you to easily control the progress direction, i.e., incremental or decremental progress by using option::ProgressType. To program a countdown progress bar, use option::ProgressType::decremental
…If you'd like to use progress bars to indicate progress while iterating over iterables, e.g., a list of numbers, this
can be achieved by using the option::MaxProgress:
…indicators supports multi-byte unicode characters in progress bars.
If the option::BarWidth is set, the library aims to respect this setting. When filling the bar, if the next Fill string has a display width that would exceed the bar width, then the library will fill the remainder of the bar with ' ' space characters instead.
See below an example of some progress bars, each with a bar width of 50, displaying different unicode characters:
…git clone https://github.com/p-ranav/indicators
cd indicators
mkdir build && cd build
cmake -DINDICATORS_SAMPLES=ON -DINDICATORS_DEMO=ON ..
makeFor Windows, if you use WinLibs like I do, the cmake command would look like this:
foo@bar:~$ mkdir build && cd build
foo@bar:~$ cmake -G "MinGW Makefiles" -DCMAKE_CXX_COMPILER="C:/WinLibs/mingw64/bin/g++.exe" -DINDICATORS_SAMPLES=ON -DINDICATORS_DEMO=ON ..
foo@bar:~$ make -j4python3 utils/amalgamate/amalgamate.py -c single_include.json -s .Contributions are welcome, have a look at the CONTRIBUTING.md document for more information.
The project is available under the MIT license.
No open issues yet, or sync has not completed.