A lightweight and customizable progress bar library for C/C++ applications, designed to provide a feature-rich yet simple API for tracking and visualizing progress in terminal-based applications.
- Displays a progress bar with percentage, elapsed time, remaining time, and processing rate.
- Supports scaling units for rate display (e.g., items/s, k-items/s).
- Fully customizable for integration into various projects.
- Includes helper functions for pretty-printing and traversal of custom structures.
- Compatible with both C and C++ projects.
- A C/C++ compiler supporting C99 or later.
-
Clone this repository:
git clone https://github.com/shivendrra/tqdm.c.git cd tqdm.c
-
Include the
tqdm.h
file in your project.
#include "tqdm.h"
#include <unistd.h> // For usleep
int main() {
tqdm bar;
init_tqdm(&bar, "Loading", false, "items", true, 100, 10);
for (int i = 0; i <= 100; ++i) {
update_tqdm(&bar, 1, false);
usleep(50000); // Simulate work
}
close_tqdm(&bar);
return 0;
}
#include "tqdm.h"
#include <thread>
#include <chrono>
int main() {
tqdm bar;
init_tqdm(&bar, "Processing", false, "tasks", true, 50, 5);
for (int i = 0; i <= 50; ++i) {
update_tqdm(&bar, 1, false);
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Simulate work
}
close_tqdm(&bar);
return 0;
}
Initializes a progress bar structure.
Updates the progress bar with the specified increment.
Displays the progress bar on the terminal.
Finalizes and disables the progress bar.
Formats a duration in seconds into an HH:MM:SS string.
Formats a numeric value into a scaled SI string (e.g., 1.2k).
Performs recursive pretty-printing for custom structures.
Performs a depth-first traversal of a structure.
Contributions are welcome! Please follow these steps:
- Fork this repository.
- Create a feature branch (
git checkout -b feature-name
). - Commit your changes (
git commit -m 'Add feature'
). - Push to the branch (
git push origin feature-name
). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.
Inspired by the Python tqdm
library. Main implementation from the TinyGrad's TQDM implementation.