Skip to content

Commit

Permalink
Fix missing color components in Counter::fmt (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
oir authored Jan 28, 2024
1 parent 7223382 commit f13770d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
20 changes: 18 additions & 2 deletions barkeep/barkeep.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,25 @@ class Counter : public AsyncDisplay {
fmt::print(*out_,
fmt::runtime(fmtstr_),
"value"_a = progress,
"speed"_a = speedom_->speed());
"speed"_a = speedom_->speed(),
"red"_a = red,
"green"_a = green,
"yellow"_a = yellow,
"blue"_a = blue,
"magenta"_a = magenta,
"cyan"_a = cyan,
"reset"_a = reset);
} else {
fmt::print(*out_, fmt::runtime(fmtstr_), "value"_a = progress);
fmt::print(*out_,
fmt::runtime(fmtstr_),
"value"_a = progress,
"red"_a = red,
"green"_a = green,
"yellow"_a = yellow,
"blue"_a = blue,
"magenta"_a = magenta,
"cyan"_a = cyan,
"reset"_a = reset);
}
return;
}
Expand Down
24 changes: 13 additions & 11 deletions tests/demo-fmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ int main(int /*argc*/, char** /*argv*/) {
namespace bk = barkeep;

for (double speed : {0., 0.1, 1.}) {
std::atomic<size_t> work{0};
auto c =
bk::Counter(&work)
.fmt(
"Picked up {value} flowers, at a speed of {speed:.1f} flowers per second")
.speed(speed);
c.show();
for (int i = 0; i < 1010; i++) {
std::this_thread::sleep_for(13ms);
work++;
for (
std::string fmtstr : {
"Picked up {value} flowers, at a speed of {speed:.1f} flowers per second",
"Picked up {blue}{value}{reset} flowers, at a speed of {green}{speed:.1f}{reset} flowers per second",
}) {
int work{0};
auto c = bk::Counter(&work).fmt(fmtstr).speed(speed);
c.show();
for (int i = 0; i < 1010; i++) {
std::this_thread::sleep_for(13ms);
work++;
}
c.done();
}
c.done();
}

for (double speed : {0., 0.1, 1.}) {
Expand Down

0 comments on commit f13770d

Please sign in to comment.