https://github.com/bmc-labs/progress_bar
Just a simple command line progress bar for C++.
https://github.com/bmc-labs/progress_bar
command-line cpp header-only
Last synced: 3 months ago
JSON representation
Just a simple command line progress bar for C++.
- Host: GitHub
- URL: https://github.com/bmc-labs/progress_bar
- Owner: bmc-labs
- License: apache-2.0
- Created: 2019-07-20T13:54:29.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-20T14:14:45.000Z (about 5 years ago)
- Last Synced: 2025-01-16T08:42:18.882Z (4 months ago)
- Topics: command-line, cpp, header-only
- Language: C++
- Homepage:
- Size: 449 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `progress_bar` - a CLI progress bar
[](https://gitlab.bmc-labs.com/libraries/progress_bar/commits/master)
I needed a command line progress bar and none of the options I found on GitHub
or via Google were much to my liking, what with their camel cased names and
lack of `operator<<` overload and such. Now this is certainly not the best ever
implementation of anything, I just hacked this together real quick. It
supposedly works on Windows, but I haven't tested that.## Using it
It's header only. It has no dependencies other than the STL and it's Apache v2
licensed.So basically you just go
```cpp
#include
#include
#include
#include
#include#include "progress_bar.h"
using namespace std::chrono_literals;
int main() {
bmc::progress_bar pb{
13, // min, also initial value
156, // max
80, // width in percent of screen (including percentage and time)
true, // auto increment when outputting
true // show time at the end
};// generate some data
std::vector vec(pb.size());
std::iota(std::begin(vec), std::end(vec), 42);for (auto & e : vec) {
e *= 2;
std::this_thread::sleep_for(50ms);
std::cout << pb;
}std::cout << pb; // if progress bar is already full, no increment happens
return 0;
}
```and you get
```shell
[-----> ] 10% - 0:42.312 elapsed
```Of course there are a bunch more things you can do. If you don't like it to
auto increment when using `operator<<`, just give it a `false` there (4th ctor
argument). You might then want to use `++` or `--` in exactly the way you'd
expect, or `step(int steps)`, or `set(int pos)`. Essentially, the following
works:
```cpp
bmc::progress_bar pb{-13, 156, 80, false, true};++pb;
pb++;
--pb;
pb--;pb.step(5); // move 5 steps forward
pb.set(137); // go to progress 137
```If you try to move outside `min` and `max`, it simply doesn't do that. If you
try to give it a `min` that is bigger than `max`, it throws. If you try to push
`width` (percentage of terminal width) to 0, it throws.## More
That's it. The example above sits in `src/main.cc` and actually does run. Other
than that - just clone this repo and/or throw the header file in your project.You're good to go.