Made with a single c++ class, which you always wanted.
Resizable bar.
Avoids redundant update by utilising ANSI escape codes.
Instant flush without a newline.
int main()
{
Bar b(20); // creates a progress bar in terminal of width 20 (excluding the braces)
for(int i = 1; i <= 1000000; i++)
{
int p = (float)i / 1000000 * 100;
b.update(p); // increments the bar as per the percentage value passed(0-100).
}
}
int main()
{
Bar b(20);
for(int i = 1; i <= 100000; i++)
{
int p = (float)i / 100000 * 100;
b.update(p);
if (p > 10)
b.finish();
}
b.finish(); // don't forget this before printing something else.
Bar a(100);
for (int i = 1; i <= 100000; i++)
{
int p = (float)i / 100000 * 100;
a.update(p);
}
}
Do not print anything before calling the finish or until the bar object goes out of scope.
- system : Ubuntu 20.10 (64bit)
- compiler: g++
- flags: -std=c++20 -o3
You can use the above mentioned ANSI escape codes to change the color, font style, etc..