https://github.com/nabijaczleweli/pb-cpp
Console progress bar for C++
https://github.com/nabijaczleweli/pb-cpp
cpp cpp-library cpp14 port progress-bar
Last synced: 9 months ago
JSON representation
Console progress bar for C++
- Host: GitHub
- URL: https://github.com/nabijaczleweli/pb-cpp
- Owner: nabijaczleweli
- License: mit
- Created: 2017-12-21T14:01:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-30T00:03:19.000Z (almost 8 years ago)
- Last Synced: 2025-04-11T19:14:08.167Z (12 months ago)
- Topics: cpp, cpp-library, cpp14, port, progress-bar
- Language: C++
- Size: 8.33 MB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Terminal progress bar for C++ [](https://travis-ci.org/nabijaczleweli/pb-cpp) [](https://ci.appveyor.com/project/nabijaczleweli/pb-cpp/branch/master) [](LICENSE)
Console progress bar for C++ inspired by [pb](https://github.com/a8m/pb).
[](https://raw.githubusercontent.com/nabijaczleweli/pb-cpp/master/demo/pb-cpp%20demo%20small.mp4)
## Examples
1. Simple example
```cpp
#include
#include
using namespace std::literals;
int main() {
const auto count = 1000u;
pb::progressbar bar(count);
bar.format("<#} >");
for(auto i = 0u; i < count; ++i) {
++bar;
std::this_thread::sleep_for(200ms);
}
bar.finish();
}
```
2. `pb::multibar` example, see full example [here](examples/multi.cpp):
```cpp
#include
#include
using namespace std::literals;
int main() {
const auto count = 100u;
pb::multibar mb;
mb.println("Application header:");
const auto bar_handler = [](auto bar, auto count) {
for(auto i = 0u; i < count; ++i) {
++bar;
std::this_thread::sleep_for(100ms);
}
bar.finish();
};
std::thread(bar_handler, mb.create_bar(count), count).detach();
mb.println("Add a separator between the two bars");
std::thread(bar_handler, mb.create_bar(count * 2), count * 2).detach();
// Start listening to all bars' changes.
// This blocks until all bars finish.
// To ignore that, run it in a different thread.
mb.listen();
}
```
3. Simple file copy
```cpp
#include
#include
int main() {
std::ifstream in_file("/usr/share/dict/words", std::ios::binary);
const auto file_size = std::ifstream("/usr/share/dict/words", std::ios::ate | std::ios::binary).tellg();
std::ofstream out_file("copy-words", std::ios::binary);
pb::progressbar bar(file_size);
bar.unit = pb::unit_t::byte;
char buf[4096];
do {
in_file.read(buf, sizeof buf);
out_file.write(buf, in_file.gcount());
bar += in_file.gcount();
} while(in_file.gcount() == sizeof buf);
bar.finish();
}
```