Skip to content

Commit

Permalink
Document iterable bar (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
oir authored May 10, 2024
1 parent 9899f4b commit 6bcba84
Show file tree
Hide file tree
Showing 5 changed files with 771 additions and 9 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> 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;
```
<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/rec/iter-bar-dark.svg" width="700">
<source media="(prefers-color-scheme: light)" srcset="docs/rec/iter-bar-light.svg" width="700">
<img src="docs/rec/iter-bar-light.svg" width="700">
</picture>
- Combine diplays using `|` operator to monitor multiple variables:
```cpp
Expand Down
20 changes: 20 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> 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;
```
<picture>
<source media="(prefers-color-scheme: dark)" srcset="rec/iter-bar-dark.svg" width="700">
<source media="(prefers-color-scheme: light)" srcset="rec/iter-bar-light.svg" width="700">
<img src="rec/iter-bar-light.svg" width="700">
</picture>
- Combine diplays using `|` operator to monitor multiple variables:
```cpp
Expand Down
Loading

0 comments on commit 6bcba84

Please sign in to comment.