From 6bcba840c81cdc8c5484b8c7dae8bb8c740c4ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20=C4=B0rsoy?= Date: Fri, 10 May 2024 17:41:53 -0400 Subject: [PATCH] Document iterable bar (#67) --- README.md | 20 ++ docs/README.md | 20 ++ docs/rec/iter-bar-dark.svg | 361 ++++++++++++++++++++++++++++++++++++ docs/rec/iter-bar-light.svg | 361 ++++++++++++++++++++++++++++++++++++ tests/demo.cpp | 18 +- 5 files changed, 771 insertions(+), 9 deletions(-) create mode 100644 docs/rec/iter-bar-dark.svg create mode 100644 docs/rec/iter-bar-light.svg diff --git a/README.md b/README.md index ab5c8b4..7f52ba7 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,26 @@ __barkeep__ strives to be [non-intrusive](https://oir.github.io/barkeep/#/README } ``` +- Automatically iterate over a container with a progress bar display + (instead of monitoring an explicit progress variable): + + ```cpp + std::vector v(300, 0); + std::iota(v.begin(), v.end(), 1); // 1, 2, 3, ..., 300 + float sum = 0; + for (auto x : bk::IterableBar(v, {.message = "Summing", .interval = .02})) { + std::this_thread::sleep_for(1.s/x); + sum += x; + } + std::cout << "Sum: " << sum << std::endl; + ``` + + + + + + + - Combine diplays using `|` operator to monitor multiple variables: ```cpp diff --git a/docs/README.md b/docs/README.md index 13ea9a3..765b1c7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -169,6 +169,26 @@ __barkeep__ also has [python bindings](https://pypi.python.org/pypi/barkeep). } ``` +- Automatically iterate over a container with a progress bar display + (instead of monitoring an explicit progress variable): + + ```cpp + std::vector v(300, 0); + std::iota(v.begin(), v.end(), 1); // 1, 2, 3, ..., 300 + float sum = 0; + for (auto x : bk::IterableBar(v, {.message = "Summing", .interval = .02})) { + std::this_thread::sleep_for(1.s/x); + sum += x; + } + std::cout << "Sum: " << sum << std::endl; + ``` + + + + + + + - Combine diplays using `|` operator to monitor multiple variables: ```cpp diff --git a/docs/rec/iter-bar-dark.svg b/docs/rec/iter-bar-dark.svg new file mode 100644 index 0000000..0ba39e3 --- /dev/null +++ b/docs/rec/iter-bar-dark.svg @@ -0,0 +1,361 @@ + + + + + + + + + + + + ~ ~ ./demo.out ~ ./demo.out ~ ./demo.out ~ ./demo.out ~ ./demo.out ~ ./demo.out ~ ./demo.out ~ ./demo.out Summing 0.00% | | 0/300 Summing 0.33% | | 1/300 Summing 0.67% |▏ | 2/300 Summing 1.00% |▎ | 3/300 Summing 1.33% |▍ | 4/300 Summing 1.67% |▌ | 5/300 Summing 2.00% |▌ | 6/300 Summing 2.33% |▋ | 7/300 Summing 2.67% |▊ | 8/300 Summing 3.00% |▉ | 9/300 Summing 3.33% |█ | 10/300 Summing 3.67% |█ | 11/300 Summing 4.00% |█▏ | 12/300 Summing 4.33% |█▎ | 13/300 Summing 4.67% |█▍ | 14/300 Summing 5.00% |█▌ | 15/300 Summing 5.33% |█▌ | 16/300 Summing 5.67% |█▋ | 17/300 Summing 6.00% |█▊ | 18/300 Summing 6.33% |█▉ | 19/300 Summing 6.67% |██ | 20/300 Summing 7.00% |██ | 21/300 Summing 7.33% |██▏ | 22/300 Summing 7.67% |██▎ | 23/300 Summing 8.00% |██▍ | 24/300 Summing 8.33% |██▌ | 25/300 Summing 8.67% |██▌ | 26/300 Summing 9.00% |██▋ | 27/300 Summing 9.33% |██▊ | 28/300 Summing 9.67% |██▉ | 29/300 Summing 10.00% |███ | 30/300 Summing 10.33% |███ | 31/300 Summing 10.67% |███▏ | 32/300 Summing 11.00% |███▎ | 33/300 Summing 11.33% |███▍ | 34/300 Summing 11.67% |███▌ | 35/300 Summing 12.00% |███▌ | 36/300 Summing 12.33% |███▋ | 37/300 Summing 12.67% |███▊ | 38/300 Summing 13.00% |███▉ | 39/300 Summing 13.33% |████ | 40/300 Summing 13.67% |████ | 41/300 Summing 14.00% |████▏ | 42/300 Summing 14.33% |████▎ | 43/300 Summing 14.67% |████▍ | 44/300 Summing 15.00% |████▌ | 45/300 Summing 15.33% |████▌ | 46/300 Summing 15.67% |████▋ | 47/300 Summing 16.00% |████▊ | 48/300 Summing 16.33% |████▉ | 49/300 Summing 16.67% |█████ | 50/300 Summing 17.00% |█████ | 51/300 Summing 17.33% |█████▏ | 52/300 Summing 18.00% |█████▍ | 54/300 Summing 18.33% |█████▌ | 55/300 Summing 18.67% |█████▌ | 56/300 Summing 19.00% |█████▋ | 57/300 Summing 19.33% |█████▊ | 58/300 Summing 19.67% |█████▉ | 59/300 Summing 20.00% |██████ | 60/300 Summing 20.33% |██████ | 61/300 Summing 20.67% |██████▏ | 62/300 Summing 21.33% |██████▍ | 64/300 Summing 21.67% |██████▌ | 65/300 Summing 22.33% |██████▋ | 67/300 Summing 22.67% |██████▊ | 68/300 Summing 23.33% |███████ | 70/300 Summing 23.67% |███████ | 71/300 Summing 24.00% |███████▏ | 72/300 Summing 24.67% |███████▍ | 74/300 Summing 25.00% |███████▌ | 75/300 Summing 25.67% |███████▋ | 77/300 Summing 26.33% |███████▉ | 79/300 Summing 26.67% |████████ | 80/300 Summing 27.33% |████████▏ | 82/300 Summing 28.00% |████████▍ | 84/300 Summing 28.33% |████████▌ | 85/300 Summing 29.00% |████████▋ | 87/300 Summing 29.67% |████████▉ | 89/300 Summing 30.33% |█████████ | 91/300 Summing 30.67% |█████████▏ | 92/300 Summing 31.33% |█████████▍ | 94/300 Summing 32.00% |█████████▌ | 96/300 Summing 32.67% |█████████▊ | 98/300 Summing 33.33% |██████████ | 100/300 Summing 34.00% |██████████▏ | 102/300 Summing 34.67% |██████████▍ | 104/300 Summing 35.33% |██████████▌ | 106/300 Summing 36.00% |██████████▊ | 108/300 Summing 36.67% |███████████ | 110/300 Summing 37.67% |███████████▎ | 113/300 Summing 38.33% |███████████▌ | 115/300 Summing 39.00% |███████████▋ | 117/300 Summing 40.00% |████████████ | 120/300 Summing 40.67% |████████████▏ | 122/300 Summing 41.67% |████████████▌ | 125/300 Summing 42.33% |████████████▋ | 127/300 Summing 43.33% |█████████████ | 130/300 Summing 44.00% |█████████████▏ | 132/300 Summing 45.00% |█████████████▌ | 135/300 Summing 46.00% |█████████████▊ | 138/300 Summing 47.00% |██████████████ | 141/300 Summing 47.67% |██████████████▎ | 143/300 Summing 48.67% |██████████████▌ | 146/300 Summing 49.33% |██████████████▊ | 148/300 Summing 50.33% |███████████████ | 151/300 Summing 51.33% |███████████████▍ | 154/300 Summing 52.33% |███████████████▋ | 157/300 Summing 53.67% |████████████████ | 161/300 Summing 54.67% |████████████████▍ | 164/300 Summing 55.67% |████████████████▋ | 167/300 Summing 56.33% |████████████████▉ | 169/300 Summing 57.67% |█████████████████▎ | 173/300 Summing 58.67% |█████████████████▌ | 176/300 Summing 60.00% |██████████████████ | 180/300 Summing 61.33% |██████████████████▍ | 184/300 Summing 62.33% |██████████████████▋ | 187/300 Summing 63.33% |███████████████████ | 190/300 Summing 64.67% |███████████████████▍ | 194/300 Summing 66.00% |███████████████████▊ | 198/300 Summing 67.33% |████████████████████▏ | 202/300 Summing 68.67% |████████████████████▌ | 206/300 Summing 70.00% |█████████████████████ | 210/300 Summing 71.67% |█████████████████████▌ | 215/300 Summing 73.00% |█████████████████████▉ | 219/300 Summing 74.33% |██████████████████████▎ | 223/300 Summing 75.67% |██████████████████████▋ | 227/300 Summing 77.33% |███████████████████████▏ | 232/300 Summing 78.67% |███████████████████████▌ | 236/300 Summing 80.33% |████████████████████████ | 241/300 Summing 81.67% |████████████████████████▌ | 245/300 Summing 83.33% |█████████████████████████ | 250/300 Summing 84.67% |█████████████████████████▍ | 254/300 Summing 86.33% |█████████████████████████▉ | 259/300 Summing 88.00% |██████████████████████████▍ | 264/300 Summing 89.33% |██████████████████████████▊ | 268/300 Summing 91.00% |███████████████████████████▎ | 273/300 Summing 92.67% |███████████████████████████▊ | 278/300 Summing 94.33% |████████████████████████████▎ | 283/300 Summing 96.33% |████████████████████████████▉ | 289/300 Summing 98.00% |█████████████████████████████▍| 294/300 Summing 99.67% |█████████████████████████████▉| 299/300 Summing 100.00% |██████████████████████████████| 300/300 Sum: 45150 ~ + \ No newline at end of file diff --git a/docs/rec/iter-bar-light.svg b/docs/rec/iter-bar-light.svg new file mode 100644 index 0000000..a80c767 --- /dev/null +++ b/docs/rec/iter-bar-light.svg @@ -0,0 +1,361 @@ + + + + + + + + + + + + ~ ~ ./demo.out ~ ./demo.out ~ ./demo.out ~ ./demo.out ~ ./demo.out ~ ./demo.out ~ ./demo.out ~ ./demo.out Summing 0.00% | | 0/300 Summing 0.33% | | 1/300 Summing 0.67% |▏ | 2/300 Summing 1.00% |▎ | 3/300 Summing 1.33% |▍ | 4/300 Summing 1.67% |▌ | 5/300 Summing 2.00% |▌ | 6/300 Summing 2.33% |▋ | 7/300 Summing 2.67% |▊ | 8/300 Summing 3.00% |▉ | 9/300 Summing 3.33% |█ | 10/300 Summing 3.67% |█ | 11/300 Summing 4.00% |█▏ | 12/300 Summing 4.33% |█▎ | 13/300 Summing 4.67% |█▍ | 14/300 Summing 5.00% |█▌ | 15/300 Summing 5.33% |█▌ | 16/300 Summing 5.67% |█▋ | 17/300 Summing 6.00% |█▊ | 18/300 Summing 6.33% |█▉ | 19/300 Summing 6.67% |██ | 20/300 Summing 7.00% |██ | 21/300 Summing 7.33% |██▏ | 22/300 Summing 7.67% |██▎ | 23/300 Summing 8.00% |██▍ | 24/300 Summing 8.33% |██▌ | 25/300 Summing 8.67% |██▌ | 26/300 Summing 9.00% |██▋ | 27/300 Summing 9.33% |██▊ | 28/300 Summing 9.67% |██▉ | 29/300 Summing 10.00% |███ | 30/300 Summing 10.33% |███ | 31/300 Summing 10.67% |███▏ | 32/300 Summing 11.00% |███▎ | 33/300 Summing 11.33% |███▍ | 34/300 Summing 11.67% |███▌ | 35/300 Summing 12.00% |███▌ | 36/300 Summing 12.33% |███▋ | 37/300 Summing 12.67% |███▊ | 38/300 Summing 13.00% |███▉ | 39/300 Summing 13.33% |████ | 40/300 Summing 13.67% |████ | 41/300 Summing 14.00% |████▏ | 42/300 Summing 14.33% |████▎ | 43/300 Summing 14.67% |████▍ | 44/300 Summing 15.00% |████▌ | 45/300 Summing 15.33% |████▌ | 46/300 Summing 15.67% |████▋ | 47/300 Summing 16.00% |████▊ | 48/300 Summing 16.33% |████▉ | 49/300 Summing 16.67% |█████ | 50/300 Summing 17.00% |█████ | 51/300 Summing 17.33% |█████▏ | 52/300 Summing 18.00% |█████▍ | 54/300 Summing 18.33% |█████▌ | 55/300 Summing 18.67% |█████▌ | 56/300 Summing 19.00% |█████▋ | 57/300 Summing 19.33% |█████▊ | 58/300 Summing 19.67% |█████▉ | 59/300 Summing 20.00% |██████ | 60/300 Summing 20.33% |██████ | 61/300 Summing 20.67% |██████▏ | 62/300 Summing 21.33% |██████▍ | 64/300 Summing 21.67% |██████▌ | 65/300 Summing 22.33% |██████▋ | 67/300 Summing 22.67% |██████▊ | 68/300 Summing 23.33% |███████ | 70/300 Summing 23.67% |███████ | 71/300 Summing 24.00% |███████▏ | 72/300 Summing 24.67% |███████▍ | 74/300 Summing 25.00% |███████▌ | 75/300 Summing 25.67% |███████▋ | 77/300 Summing 26.33% |███████▉ | 79/300 Summing 26.67% |████████ | 80/300 Summing 27.33% |████████▏ | 82/300 Summing 28.00% |████████▍ | 84/300 Summing 28.33% |████████▌ | 85/300 Summing 29.00% |████████▋ | 87/300 Summing 29.67% |████████▉ | 89/300 Summing 30.33% |█████████ | 91/300 Summing 30.67% |█████████▏ | 92/300 Summing 31.33% |█████████▍ | 94/300 Summing 32.00% |█████████▌ | 96/300 Summing 32.67% |█████████▊ | 98/300 Summing 33.33% |██████████ | 100/300 Summing 34.00% |██████████▏ | 102/300 Summing 34.67% |██████████▍ | 104/300 Summing 35.33% |██████████▌ | 106/300 Summing 36.00% |██████████▊ | 108/300 Summing 36.67% |███████████ | 110/300 Summing 37.67% |███████████▎ | 113/300 Summing 38.33% |███████████▌ | 115/300 Summing 39.00% |███████████▋ | 117/300 Summing 40.00% |████████████ | 120/300 Summing 40.67% |████████████▏ | 122/300 Summing 41.67% |████████████▌ | 125/300 Summing 42.33% |████████████▋ | 127/300 Summing 43.33% |█████████████ | 130/300 Summing 44.00% |█████████████▏ | 132/300 Summing 45.00% |█████████████▌ | 135/300 Summing 46.00% |█████████████▊ | 138/300 Summing 47.00% |██████████████ | 141/300 Summing 47.67% |██████████████▎ | 143/300 Summing 48.67% |██████████████▌ | 146/300 Summing 49.33% |██████████████▊ | 148/300 Summing 50.33% |███████████████ | 151/300 Summing 51.33% |███████████████▍ | 154/300 Summing 52.33% |███████████████▋ | 157/300 Summing 53.67% |████████████████ | 161/300 Summing 54.67% |████████████████▍ | 164/300 Summing 55.67% |████████████████▋ | 167/300 Summing 56.33% |████████████████▉ | 169/300 Summing 57.67% |█████████████████▎ | 173/300 Summing 58.67% |█████████████████▌ | 176/300 Summing 60.00% |██████████████████ | 180/300 Summing 61.33% |██████████████████▍ | 184/300 Summing 62.33% |██████████████████▋ | 187/300 Summing 63.33% |███████████████████ | 190/300 Summing 64.67% |███████████████████▍ | 194/300 Summing 66.00% |███████████████████▊ | 198/300 Summing 67.33% |████████████████████▏ | 202/300 Summing 68.67% |████████████████████▌ | 206/300 Summing 70.00% |█████████████████████ | 210/300 Summing 71.67% |█████████████████████▌ | 215/300 Summing 73.00% |█████████████████████▉ | 219/300 Summing 74.33% |██████████████████████▎ | 223/300 Summing 75.67% |██████████████████████▋ | 227/300 Summing 77.33% |███████████████████████▏ | 232/300 Summing 78.67% |███████████████████████▌ | 236/300 Summing 80.33% |████████████████████████ | 241/300 Summing 81.67% |████████████████████████▌ | 245/300 Summing 83.33% |█████████████████████████ | 250/300 Summing 84.67% |█████████████████████████▍ | 254/300 Summing 86.33% |█████████████████████████▉ | 259/300 Summing 88.00% |██████████████████████████▍ | 264/300 Summing 89.33% |██████████████████████████▊ | 268/300 Summing 91.00% |███████████████████████████▎ | 273/300 Summing 92.67% |███████████████████████████▊ | 278/300 Summing 94.33% |████████████████████████████▎ | 283/300 Summing 96.33% |████████████████████████████▉ | 289/300 Summing 98.00% |█████████████████████████████▍| 294/300 Summing 99.67% |█████████████████████████████▉| 299/300 Summing 100.00% |██████████████████████████████| 300/300 Sum: 45150 ~ + \ No newline at end of file diff --git a/tests/demo.cpp b/tests/demo.cpp index 12236f8..ad014da 100644 --- a/tests/demo.cpp +++ b/tests/demo.cpp @@ -1,5 +1,6 @@ #include #include +#include #include int main(int /*argc*/, char** /*argv*/) { @@ -14,14 +15,11 @@ int main(int /*argc*/, char** /*argv*/) { anim.done(); } - { - std::vector stills{ - "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}; + { // Custom animation stills + std::vector stills{"⠋", "⠙", "⠸", "⠴", "⠦", "⠇"}; auto anim = bk::Animation( {.message = "Working", .style = stills, .interval = 0.5s}); - anim.show(); std::this_thread::sleep_for(10s); - anim.done(); } std::vector> speeds{std::nullopt, 0, 0.1, 1}; @@ -187,10 +185,12 @@ int main(int /*argc*/, char** /*argv*/) { } { // Iterable automatic progress bar - std::vector v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - int sum = 0; - for (auto x : bk::IterableBar(v, {.message = "Summing"})) { - std::this_thread::sleep_for(1s); + + std::vector v(300, 0); + std::iota(v.begin(), v.end(), 1); // 1, 2, 3, ..., 300 + float sum = 0; + for (auto x : bk::IterableBar(v, {.message = "Summing", .interval = .02})) { + std::this_thread::sleep_for(1.s / x); sum += x; } std::cout << "Sum: " << sum << std::endl;