From 17778f4fae4683dc7317c5fb4f0365579102ae80 Mon Sep 17 00:00:00 2001 From: oir Date: Sun, 18 Feb 2024 15:41:44 -0500 Subject: [PATCH] Update other README --- README.md | 94 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 281b4fe..5c013e5 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,10 @@ Small, single C++ header to display async animations, counters, and progress bars. Use it by including `barkeep.h` in your project. +__barkeep__ strives to be [non-intrusive](https://oir.github.io/barkeep/#/README?id=non-intrusive-design). **barkeep** also has [python bindings](https://pypi.python.org/pypi/barkeep). - Build status Coverage status c++17 #include <barkeep/barkeep.h> + Build status Coverage status c++20 #include <barkeep/barkeep.h>
Build status pypi pip install barkeep @@ -21,8 +22,8 @@ Use it by including `barkeep.h` in your project. ```cpp using namespace std::chrono_literals; namespace bk = barkeep; - - auto anim = bk::Animation().message("Working"); + + auto anim = bk::Animation({.message = "Working"}); anim.show(); /* do work */ std::this_thread::sleep_for(10s); anim.done(); @@ -37,7 +38,7 @@ Use it by including `barkeep.h` in your project. - Supports several styles: ```cpp - auto anim = bk::Animation().message("Downloading...").style(bk::Earth); + auto anim = bk::Animation({.message = "Downloading...", .style = bk::Earth}); ``` @@ -50,10 +51,11 @@ Use it by including `barkeep.h` in your project. ```cpp int work{0}; - auto c = bk::Counter(&work) - .message("Reading lines") - .speed(1.) - .speed_unit("line/s"); + auto c = bk::Counter(&work, { + .message = "Reading lines", + .speed = 1., + .speed_unit = "line/s" + }); c.show(); for (int i = 0; i < 505; i++) { std::this_thread::sleep_for(13ms); // read & process line @@ -72,11 +74,12 @@ Use it by including `barkeep.h` in your project. ```cpp int work{0}; - auto bar = bk::ProgressBar(&work) - .message("Reading lines") - .speed(1.) - .speed_unit("line/s") - .total(505); + auto bar = bk::ProgressBar(&work, { + .total = 505, + .message = "Reading lines", + .speed = 1., + .speed_unit = "line/s", + }); bar.show(); for (int i = 0; i < 505; i++) { std::this_thread::sleep_for(13ms); // read & process line @@ -95,12 +98,13 @@ Use it by including `barkeep.h` in your project. ```cpp int work{0}; - auto bar = bk::ProgressBar(&work) - .message("Reading lines") - .speed(1.) - .speed_unit("line/s") - .total(505) - .style(bk::ProgressBarStyle::Pip); + auto bar = bk::ProgressBar(&work, { + .total = 505, + .message = "Reading lines", + .speed = 1., + .speed_unit = "line/s", + .style = bk::ProgressBarStyle::Pip, + }); bar.show(); for (int i = 0; i < 505; i++) { std::this_thread::sleep_for(13ms); // read & process line @@ -120,8 +124,8 @@ Use it by including `barkeep.h` in your project. ```cpp std::atomic sents{0}, toks{0}; auto bar = - bk::ProgressBar(&sents).total(1010).message("Sents") | - bk::Counter(&toks).message("Toks").speed_unit("tok/s").speed(1.); + bk::ProgressBar(&sents, {.total = 1010, .message = "Sents"}) | + bk::Counter(&toks, {.message = "Toks", .speed = 1., .speed_unit = "tok/s"}); bar.show(); for (int i = 0; i < 1010; i++) { // do work @@ -141,18 +145,18 @@ Use it by including `barkeep.h` in your project. - Use "no tty" mode to, e.g., output to log files: ```cpp - std::atomic sents{0}, toks{0}; - auto bar = bk::ProgressBar(&sents) - .total(401) - .message("Sents") - .speed(1.) - .interval(1.) - .no_tty(); + std::atomic sents{0}; + auto bar = bk::ProgressBar(&sents, { + .total = 401, + .message = "Sents", + .speed = 1., + .interval = 1., + .no_tty = true, + }); bar.show(); for (int i = 0; i < 401; i++) { std::this_thread::sleep_for(13ms); sents++; - toks += (1 + rand() % 5); } bar.done(); ``` @@ -174,15 +178,16 @@ See `demo.cpp` for more examples. You can enable advanced formatting by defining the `BARKEEP_ENABLE_FMT` compile-time flag, at the expense of introducing a dependency to [`fmt`](https://github.com/fmtlib/fmt) (which has an optional header-only mode). -In this case, `Counter`s and `ProgressBar`s have an additional method `fmt()` which can be used to format the display using a `fmt`-like format string: +In this case, `Counter`s and `ProgressBar`s have an additional `Config` option `format` which can be used to format the display using a `fmt`-like format string: - A counter: ```cpp size_t work{0}; - auto c = bk::Counter(&work) - .fmt("Picked up {value} flowers, at {speed:.1f} flo/s") - .speed(0.1); + auto c = bk::Counter(&work, { + .format = "Picked up {value} flowers, at {speed:.1f} flo/s", + .speed = 0.1 + }); c.show(); for (int i = 0; i < 1010; i++) { std::this_thread::sleep_for(13ms), work++; } c.done(); @@ -198,11 +203,11 @@ In this case, `Counter`s and `ProgressBar`s have an additional method `fmt()` wh ```cpp size_t work{0}; - auto bar = - bk::ProgressBar(&work) - .total(1010) - .fmt("Picking flowers {value:4d}/{total} {bar} ({speed:.1f} flo/s)") - .speed(0.1); + auto bar = bk::ProgressBar( + &work, + {.total = 1010, + .format = "Picking flowers {value:4d}/{total} {bar} ({speed:.1f} flo/s)", + .speed = 0.1}); bar.show(); for (int i = 0; i < 1010; i++) { std::this_thread::sleep_for(9ms), work++; } bar.done(); @@ -214,7 +219,7 @@ In this case, `Counter`s and `ProgressBar`s have an additional method `fmt()` wh -When `fmt()` is used, other textual parameters, such as the ones passed by `message()` or `speed_unit()` are ignored. +When `format` is used, other textual parameters, such as `message` or `speed_unit` are ignored. - For counters, you can use the predefined identifiers `{value}`, and `{speed}`. - With bars, you can use `{value}`, `{bar}`, `{percent}`, `{total}`, and `{speed}`. @@ -222,11 +227,12 @@ When `fmt()` is used, other textual parameters, such as the ones passed by `mess Additionally, some basic ansi color sequences are predefined as identifiers which could be used to add color: ```cpp std::atomic work{0}; -auto bar = bk::ProgressBar(&work) - .total(1010) - .fmt("Picking flowers {blue}{value:4d}/{total} {green}{bar} " - "{yellow}{percent:3.0f}%{reset} ({speed:.1f} flo/s)") - .speed(0.1); +auto bar = bk::ProgressBar( + &work, + {.total = 1010, + .format = "Picking flowers {blue}{value:4d}/{total} {green}{bar} " + "{yellow}{percent:3.0f}%{reset} ({speed:.1f} flo/s)", + .speed = 0.1}); bar.show(); for (int i = 0; i < 1010; i++) { std::this_thread::sleep_for(9ms), work++; } bar.done();