Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python bindings #12

Merged
merged 12 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
*.out.*

*.gcno
*.gcda
*.gcda

subprojects/*/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2021 Ozan Irsoy
Copyright 2023 Ozan Irsoy

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ including `meanwhile.h` in your project.

```C++
int work{0};
auto c = Counter(work)
auto c = Counter(&work)
.message("Reading lines")
.speed(Speed::Last)
.speed_unit("line/s");
Expand All @@ -64,7 +64,7 @@ including `meanwhile.h` in your project.

```C++
int work{0};
auto bar = ProgressBar(work)
auto bar = ProgressBar(&work)
.message("Reading lines")
.speed(Speed::Last)
.speed_unit("line/s")
Expand All @@ -87,8 +87,8 @@ including `meanwhile.h` in your project.
```C++
std::atomic<size_t> sents{0}, toks{0};
auto bar =
ProgressBar(sents).total(1010).message("Sents") |
Counter(toks).message("Toks").speed_unit("tok/s").speed(Speed::Last);
ProgressBar(&sents).total(1010).message("Sents") |
Counter(&toks).message("Toks").speed_unit("tok/s").speed(Speed::Last);
bar.show();
for (int i = 0; i < 1010; i++) {
// do work
Expand All @@ -108,7 +108,7 @@ including `meanwhile.h` in your project.

```C++
std::atomic<size_t> sents{0}, toks{0};
auto bar = ProgressBar(sents)
auto bar = ProgressBar(&sents)
.total(401)
.message("Sents")
.speed(Speed::Last)
Expand Down
34 changes: 19 additions & 15 deletions demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ int main(int /*argc*/, char** /*argv*/) {
anim.done();
}

for (auto speed : {Speed::None, Speed::Overall, Speed::Last, Speed::Both}) {
for (auto speed : {Speed::None, Speed::Overall, Speed::Last}) {
std::atomic<size_t> work{0};
auto c =
Counter(work).message("Doing stuff").speed_unit("tk/s").speed(speed);
Counter(&work).message("Doing stuff").speed_unit("tk/s").speed(speed);
c.show();
for (int i = 0; i < 1010; i++) {
std::this_thread::sleep_for(13ms);
Expand All @@ -27,10 +27,10 @@ int main(int /*argc*/, char** /*argv*/) {
c.done();
}

for (auto speed : {Speed::None, Speed::Overall, Speed::Last, Speed::Both}) {
for (auto speed : {Speed::None, Speed::Overall, Speed::Last}) {
float work{0};
auto c =
Counter(work).message("Doing stuff").speed_unit("tk/s").speed(speed);
Counter(&work).message("Doing stuff").speed_unit("tk/s").speed(speed);
c.show();
for (int i = 0; i < 1010; i++) {
std::this_thread::sleep_for(13ms);
Expand All @@ -39,9 +39,9 @@ int main(int /*argc*/, char** /*argv*/) {
c.done();
}

for (auto speed : {Speed::None, Speed::Overall, Speed::Last, Speed::Both}) {
for (auto speed : {Speed::None, Speed::Overall, Speed::Last}) {
unsigned long long work{677};
auto c = Counter(work).message("Decreasing").speed_unit("").speed(speed);
auto c = Counter(&work).message("Decreasing").speed_unit("").speed(speed);
c.show();
while (work > 0) {
std::this_thread::sleep_for(13ms);
Expand All @@ -50,10 +50,10 @@ int main(int /*argc*/, char** /*argv*/) {
// Let destructor do the c.done() this time
}

for (auto speed : {Speed::None, Speed::Overall, Speed::Last, Speed::Both}) {
for (auto sty : {Blocks, Bars}) {
for (auto speed : {Speed::None, Speed::Overall, Speed::Last}) {
for (auto sty : {Blocks, Bars, Arrow}) {
std::atomic<size_t> work{0};
auto bar = ProgressBar(work)
auto bar = ProgressBar(&work)
.total(1010)
.message("Doing stuff")
.speed_unit("tk/s")
Expand All @@ -73,8 +73,8 @@ int main(int /*argc*/, char** /*argv*/) {
// in terms of tokens per second.'
std::atomic<size_t> sents{0}, toks{0};
auto bar =
ProgressBar(sents).total(1010).message("Sents") |
Counter(toks).message("Toks").speed_unit("tok/s").speed(Speed::Last);
ProgressBar(&sents).total(1010).message("Sents") |
Counter(&toks).message("Toks").speed_unit("tok/s").speed(Speed::Last);
bar.show();
for (int i = 0; i < 1010; i++) {
std::this_thread::sleep_for(13ms);
Expand All @@ -87,7 +87,7 @@ int main(int /*argc*/, char** /*argv*/) {
{ // Decreasing progress
// WARN: negative speeds will underflow if you use an unsigned progress type
long work{1010};
auto bar = ProgressBar(work).total(1010).speed(Speed::Last);
auto bar = ProgressBar(&work).total(1010).speed(Speed::Last);
bar.show();
for (int i = 0; i < 1010; i++) {
std::this_thread::sleep_for(13ms);
Expand All @@ -96,9 +96,13 @@ int main(int /*argc*/, char** /*argv*/) {
bar.done();
}

std::cout << "\nWarning: To illustrate infrequent writes, no-tty"
" demos take long (several minutes)... 😅"
<< std::endl;

{ // Progress bar with no-tty mode
std::atomic<size_t> sents{0}, toks{0};
auto bar = ProgressBar(sents)
auto bar = ProgressBar(&sents)
.total(20100)
.message("Sents")
.speed(Speed::Last)
Expand All @@ -115,8 +119,8 @@ int main(int /*argc*/, char** /*argv*/) {
{ // Composite display of a ProgressBar and Counter with no-tty mode
std::atomic<size_t> sents{0}, toks{0};
auto bar =
ProgressBar(sents).total(20100).message("Sents") |
Counter(toks).message("Toks").speed_unit("tok/s").speed(Speed::Last);
ProgressBar(&sents).total(20100).message("Sents") |
Counter(&toks).message("Toks").speed_unit("tok/s").speed(Speed::Last);
bar.no_tty();
bar.show();
for (int i = 0; i < 20100; i++) {
Expand Down
Loading