mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-14 03:08:52 +08:00
Updated demo code
This commit is contained in:
@@ -6,6 +6,7 @@ int main() {
|
||||
|
||||
// Hide cursor
|
||||
std::cout << "\e[?25l";
|
||||
|
||||
{
|
||||
//
|
||||
// PROGRESS BAR 1
|
||||
@@ -44,67 +45,73 @@ int main() {
|
||||
thread.join();
|
||||
}
|
||||
|
||||
{
|
||||
//
|
||||
// PROGRESS BAR 3
|
||||
// PROGRESS BAR 2
|
||||
//
|
||||
indica::ProgressBar p3;
|
||||
p3.set_bar_width(40);
|
||||
p3.set_prefix_text("Reading package list... ");
|
||||
p3.start_bar_with("");
|
||||
p3.fill_bar_progress_with("");
|
||||
p3.lead_bar_progress_with("");
|
||||
p3.fill_bar_remainder_with("");
|
||||
p3.end_bar_with("");
|
||||
p3.set_foreground_color(indica::Color::WHITE);
|
||||
p3.hide_percentage();
|
||||
auto job3 = [&p3]() {
|
||||
indica::ProgressBar p;
|
||||
p.set_bar_width(40);
|
||||
p.set_prefix_text("Reading package list... ");
|
||||
p.start_bar_with("");
|
||||
p.fill_bar_progress_with("");
|
||||
p.lead_bar_progress_with("");
|
||||
p.fill_bar_remainder_with("");
|
||||
p.end_bar_with("");
|
||||
p.set_foreground_color(indica::Color::WHITE);
|
||||
p.hide_percentage();
|
||||
auto job = [&p]() {
|
||||
while (true) {
|
||||
p3.set_prefix_text("Reading package list... " +
|
||||
std::to_string(p3.current()) + "% ");
|
||||
if (p3.current() + 2 >= 100)
|
||||
p3.set_prefix_text("Reading package list... Done");
|
||||
p3.tick();
|
||||
if (p3.is_completed()) {
|
||||
p.set_prefix_text("Reading package list... " +
|
||||
std::to_string(p.current()) + "% ");
|
||||
if (p.current() + 2 >= 100)
|
||||
p.set_prefix_text("Reading package list... Done");
|
||||
p.tick();
|
||||
if (p.is_completed()) {
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(25));
|
||||
}
|
||||
};
|
||||
std::thread thread3(job3);
|
||||
thread3.join();
|
||||
std::thread thread(job);
|
||||
thread.join();
|
||||
}
|
||||
|
||||
{
|
||||
//
|
||||
// PROGRESS BAR 2
|
||||
// PROGRESS BAR 3
|
||||
//
|
||||
indica::ProgressBar p2;
|
||||
p2.set_bar_width(50);
|
||||
p2.start_bar_with("[");
|
||||
p2.fill_bar_progress_with("=");
|
||||
p2.lead_bar_progress_with(">");
|
||||
p2.fill_bar_remainder_with(" ");
|
||||
p2.end_bar_with("]");
|
||||
p2.set_postfix_text("Getting started");
|
||||
p2.set_foreground_color(indica::Color::GREEN);
|
||||
auto job2 = [&p2]() {
|
||||
indica::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("]");
|
||||
p.set_postfix_text("Getting started");
|
||||
p.set_foreground_color(indica::Color::GREEN);
|
||||
auto job = [&p]() {
|
||||
while (true) {
|
||||
auto ticks = p2.current();
|
||||
auto ticks = p.current();
|
||||
if (ticks > 20 && ticks < 50)
|
||||
p2.set_postfix_text("Delaying the inevitable");
|
||||
p.set_postfix_text("Delaying the inevitable");
|
||||
else if (ticks > 50 && ticks < 80)
|
||||
p2.set_postfix_text("Crying quietly");
|
||||
p.set_postfix_text("Crying quietly");
|
||||
else if (ticks > 80 && ticks < 98)
|
||||
p2.set_postfix_text("Almost there");
|
||||
p.set_postfix_text("Almost there");
|
||||
else if (ticks >= 98)
|
||||
p2.set_postfix_text("Done");
|
||||
p2.tick();
|
||||
if (p2.is_completed())
|
||||
p.set_postfix_text("Done");
|
||||
p.tick();
|
||||
if (p.is_completed())
|
||||
break;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(30));
|
||||
}
|
||||
};
|
||||
std::thread thread2(job2);
|
||||
thread2.join();
|
||||
std::thread thread(job);
|
||||
thread.join();
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
//
|
||||
// PROGRESS BAR 4
|
||||
//
|
||||
@@ -180,7 +187,12 @@ int main() {
|
||||
thread.join();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
//
|
||||
// PROGRESS BAR 5
|
||||
//
|
||||
indica::ProgressSpinner p;
|
||||
p.set_prefix_text("");
|
||||
p.set_postfix_text("Checking credentials");
|
||||
@@ -207,6 +219,9 @@ int main() {
|
||||
|
||||
std::cout << " Compiling mission\n";
|
||||
{
|
||||
//
|
||||
// PROGRESS BAR 6
|
||||
//
|
||||
indica::ProgressSpinner p;
|
||||
p.set_prefix_text(" - ");
|
||||
p.set_postfix_text("Searching for the Moon");
|
||||
|
||||
Reference in New Issue
Block a user