Files
indicators/test/bar.cpp

63 lines
1.3 KiB
C++
Raw Normal View History

2019-12-03 19:59:43 -06:00
#include <progress/bar.hpp>
2019-12-03 21:55:38 -06:00
#include <vector>
2019-12-03 19:59:43 -06:00
int main() {
2019-12-03 21:25:22 -06:00
2019-12-03 19:59:43 -06:00
ProgressBar bar;
// Configure progress bar
bar.bar_width(50);
2019-12-03 19:59:43 -06:00
bar.start_with("[");
2019-12-03 20:40:34 -06:00
bar.fill_progress_with("");
bar.lead_progress_with("");
bar.fill_remainder_with("-");
2019-12-03 21:25:22 -06:00
bar.end_with(" ]");
2019-12-03 21:55:38 -06:00
bar.color(ProgressBar::Color::YELLOW);
2019-12-03 19:59:43 -06:00
// As configured, the bar will look like this:
2019-12-03 21:25:22 -06:00
//
// [■■■■■■■■■■■■■■■■■■■■--------] 70%
2019-12-03 19:59:43 -06:00
//
//
2019-12-03 21:55:38 -06:00
std::atomic<size_t> index{0};
std::vector<std::string> status_text =
{
"Rocket.exe is not responding",
"Finding a replacement engineer",
"Buying more snacks",
"Assimilating the modding community",
"Crossing fingers",
"Porting KSP to a Nokia 3310"
"Flexing struts",
"Releasing space whales",
"Watching paint dry"
};
auto job = [&bar, &index, &status_text]() {
2019-12-03 21:25:22 -06:00
while (true) {
2019-12-03 21:55:38 -06:00
if (bar.completed()) {
2019-12-03 21:25:22 -06:00
break;
2019-12-03 21:55:38 -06:00
}
bar.append_text(status_text[index % status_text.size()]);
2019-12-03 21:25:22 -06:00
bar.tick();
2019-12-03 21:55:38 -06:00
index += 1;
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
2019-12-03 21:25:22 -06:00
}
};
std::thread first_job(job);
std::thread second_job(job);
std::thread third_job(job);
std::thread last_job(job);
first_job.join();
second_job.join();
third_job.join();
last_job.join();
2019-12-03 19:59:43 -06:00
2019-12-03 21:25:22 -06:00
std::cout << "Done\n";
2019-12-03 19:59:43 -06:00
return 0;
}