Skip to content

A simple implementation of terminal progress bar in C++.

License

Notifications You must be signed in to change notification settings

yomf/terminal-progress-bar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

A simple terminal progress bar

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.

Usage

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).
    }
}

Example

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);
    }
}

Output

output screenshot

Don'ts

Do not print anything before calling the finish or until the bar object goes out of scope.

Test Configurations:

  • system : Ubuntu 20.10 (64bit)
  • compiler: g++
  • flags: -std=c++20 -o3

Contributions

You can use the above mentioned ANSI escape codes to change the color, font style, etc..

License

MIT

Releases

No releases published

Packages

No packages published

Languages