Skip to content

c-modules/c_progress_bar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C Progress Bar

A simple progress bar library for C. Example Image (C Progress Bar)

Features

  • Colorful progress bar
  • Remaining time estimation
  • Elapsed time tracking
  • Works with MSVC, Clang and GCC
  • Written in C99 with minimal dependencies

Limitations

  • The progress bar only prints when you call update
  • If you print anything when the progress bar is running, it may be
    • overwritten by the progress bar if there is no \n
    • appended to the end if there is \n Example Image (C Progress Bar)

Sample Usage

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include "c_progress_bar.h"

#define N 1000000000

int main(void)
{
    double sum = 0.0;

    // Setup progress bar
    CPB_Config config = cpb_get_default_config();
    config.description = "Processing";                // Default: ""
    config.min_refresh_time = 0.1;                    // Minimum refresh time in seconds. Default: 0.1.
    config.timer_remaining_time_recent_weight = 0.3;  // Weight for recent rate in remaining time estimation. Range: [0, 1]. Default: 0.3.

    // You don't need to modify anything for CPB_ProgressBar.
    // Just call cpb_init
    CPB_ProgressBar progress_bar;
    cpb_init(&progress_bar, 0, N, config);

    // Main loop
    cpb_start(&progress_bar);
    for (int64_t i = 0; i <= N; i++)
    {
        if (i % 1000 == 0)
        {
            cpb_update(&progress_bar, i);
        }

        sum += (i % 100) * 0.0001;
    }
    cpb_finish(&progress_bar);

    printf("Final result: %f\n", sum);

    return 0;
}

About

A simple progress bar library for C

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published