mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-14 03:08:52 +08:00
Added sample showing progress spinner
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <indicator/progressbar.hpp>
|
||||
#include <indicator/progress_bar.hpp>
|
||||
#include <indicator/progress_spinner.hpp>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
@@ -161,6 +162,7 @@ int main() {
|
||||
p4.lead_bar_progress_with(lead_spinner[index4 % lead_spinner.size()]);
|
||||
index4 += 1;
|
||||
if (p4.current() + 2 >= 100) {
|
||||
std::cout << std::endl;
|
||||
p4.set_foreground_color(indicator::Color::RED);
|
||||
p4.set_prefix_text("{ ERROR } ");
|
||||
p4.show_percentage();
|
||||
@@ -209,37 +211,29 @@ int main() {
|
||||
}
|
||||
|
||||
{
|
||||
indicator::ProgressBar p;
|
||||
p.set_bar_width(50);
|
||||
p.start_bar_with("");
|
||||
p.fill_bar_progress_with("");
|
||||
p.lead_bar_progress_with("");
|
||||
p.fill_bar_remainder_with("");
|
||||
p.end_bar_with("");
|
||||
indicator::ProgressSpinner p;
|
||||
p.set_postfix_text("Checking credentials");
|
||||
p.set_foreground_color(indicator::Color::YELLOW);
|
||||
std::atomic<int> spinner_index{0};
|
||||
std::vector<std::string> spinner{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"};
|
||||
auto job = [&p, &spinner_index, &spinner]() {
|
||||
p.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"});
|
||||
auto job = [&p]() {
|
||||
while (true) {
|
||||
p.set_prefix_text(spinner[spinner_index % spinner.size()]);
|
||||
p.tick();
|
||||
spinner_index -= 1;
|
||||
if (p.current() + 2 >= 100) {
|
||||
std::cout << std::endl;
|
||||
if (p.is_completed()) {
|
||||
p.set_foreground_color(indicator::Color::GREEN);
|
||||
p.set_prefix_text("✔");
|
||||
p.hide_spinner();
|
||||
p.hide_percentage();
|
||||
p.set_postfix_text("Authenticated!");
|
||||
p.mark_as_completed();
|
||||
break;
|
||||
}
|
||||
else
|
||||
p.tick();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(60));
|
||||
}
|
||||
};
|
||||
std::thread thread(job);
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user