Instantiator
Generate c++ template instantiations
Loading...
Searching...
No Matches
ProgressBar.cpp
Go to the documentation of this file.
1#include "IO/ProgressBar.hpp"
2
3#include <string>
4
5#include <fmt/color.h>
6#include <fmt/core.h>
7
8void ProgressBar::step(std::string message)
9{
10 curr = curr + 1;
11 draw(message);
12}
13
14void ProgressBar::update(int curr_in, std::string message)
15{
16 curr = curr_in;
17 draw(message);
18}
19
20void ProgressBar::draw(std::string message) const
21{
22 int reps_done = static_cast<int>(curr * scaling);
23 int reps_do = 100 - reps_done;
24 std::string fmt_done = fmt::format("{{:{}>{}}}", fill_done, reps_done);
25 std::string fmt_do = fmt::format("{{:{}>{}}}", fill_do, reps_do);
26
27 fmt::print("\r[");
28 if(reps_done > 0) {
29 auto tmp_done = fmt::vformat(fmt_done, fmt::make_format_args(fill_done));
30 fmt::print(fg(style.fg_done) | bg(style.bg_done) | fmt::emphasis::bold, "{}", tmp_done);
31 }
32 if(100 - reps_done > 0) {
33 auto tmp_do = fmt::vformat(fmt_do, fmt::make_format_args(fill_do));
34 fmt::print(fg(style.fg_do) | bg(style.bg_do), "{}", tmp_do);
35 }
36 fmt::print("]");
37 fmt::print(fg(style.fg_percent) | bg(style.bg_percent) | fmt::emphasis::bold, " {:.2f}%", curr * scaling);
38 fmt::print(fg(style.fg_message) | bg(style.bg_message), " {}", message);
39 fflush(stdout);
40}
void update(int curr, std::string message="")
std::string fill_done
std::string fill_do
void step(std::string message="")
void draw(std::string message="") const
ProgressStyle style
fmt::color fg_message
fmt::color bg_message
fmt::color fg_percent
fmt::color bg_do
fmt::color bg_done
fmt::color bg_percent
fmt::color fg_do
fmt::color fg_done