mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-15 03:38:53 +08:00
Minor updates in preparation for GIF recording
This commit is contained in:
@@ -42,6 +42,7 @@ int main() {
|
|||||||
|
|
||||||
// Hide cursor
|
// Hide cursor
|
||||||
std::cout << "\e[?25l";
|
std::cout << "\e[?25l";
|
||||||
|
std::cout << "\n\n";
|
||||||
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ int main() {
|
|||||||
//
|
//
|
||||||
indica::ProgressBar p1;
|
indica::ProgressBar p1;
|
||||||
p1.set_bar_width(50);
|
p1.set_bar_width(50);
|
||||||
p1.start_bar_with("[");
|
p1.start_bar_with(" [");
|
||||||
p1.fill_bar_progress_with("■");
|
p1.fill_bar_progress_with("■");
|
||||||
p1.lead_bar_progress_with("■");
|
p1.lead_bar_progress_with("■");
|
||||||
p1.fill_bar_remainder_with(" ");
|
p1.fill_bar_remainder_with(" ");
|
||||||
@@ -86,7 +87,7 @@ int main() {
|
|||||||
//
|
//
|
||||||
indica::ProgressBar p3;
|
indica::ProgressBar p3;
|
||||||
p3.set_bar_width(40);
|
p3.set_bar_width(40);
|
||||||
p3.set_prefix_text("Reading package list... ");
|
p3.set_prefix_text(" Reading package list... ");
|
||||||
p3.start_bar_with("");
|
p3.start_bar_with("");
|
||||||
p3.fill_bar_progress_with("");
|
p3.fill_bar_progress_with("");
|
||||||
p3.lead_bar_progress_with("");
|
p3.lead_bar_progress_with("");
|
||||||
@@ -96,9 +97,10 @@ int main() {
|
|||||||
p3.hide_percentage();
|
p3.hide_percentage();
|
||||||
auto job3 = [&p3]() {
|
auto job3 = [&p3]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
p3.set_prefix_text("Reading package list... " + std::to_string(p3.current()) + "% ");
|
p3.set_prefix_text(" Reading package list... " +
|
||||||
|
std::to_string(p3.current()) + "% ");
|
||||||
if (p3.current() + 2 >= 100)
|
if (p3.current() + 2 >= 100)
|
||||||
p3.set_prefix_text("Reading package list... Done");
|
p3.set_prefix_text(" Reading package list... Done");
|
||||||
p3.tick();
|
p3.tick();
|
||||||
if (p3.is_completed()) {
|
if (p3.is_completed()) {
|
||||||
break;
|
break;
|
||||||
@@ -114,7 +116,7 @@ int main() {
|
|||||||
//
|
//
|
||||||
indica::ProgressBar p2;
|
indica::ProgressBar p2;
|
||||||
p2.set_bar_width(50);
|
p2.set_bar_width(50);
|
||||||
p2.start_bar_with("[");
|
p2.start_bar_with(" [");
|
||||||
p2.fill_bar_progress_with("=");
|
p2.fill_bar_progress_with("=");
|
||||||
p2.lead_bar_progress_with(">");
|
p2.lead_bar_progress_with(">");
|
||||||
p2.fill_bar_remainder_with(" ");
|
p2.fill_bar_remainder_with(" ");
|
||||||
@@ -144,9 +146,10 @@ int main() {
|
|||||||
//
|
//
|
||||||
// PROGRESS BAR 4
|
// PROGRESS BAR 4
|
||||||
//
|
//
|
||||||
std::vector<std::string> lead_spinner{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"};
|
std::vector<std::string> lead_spinner{"⠋", "⠙", "⠹", "⠸", "⠼",
|
||||||
|
"⠴", "⠦", "⠧", "⠇", "⠏"};
|
||||||
indica::ProgressBar p4;
|
indica::ProgressBar p4;
|
||||||
p4.set_bar_width(50);
|
p4.set_bar_width(40);
|
||||||
p4.start_bar_with("");
|
p4.start_bar_with("");
|
||||||
p4.fill_bar_progress_with("⠸");
|
p4.fill_bar_progress_with("⠸");
|
||||||
p4.lead_bar_progress_with("");
|
p4.lead_bar_progress_with("");
|
||||||
@@ -158,13 +161,13 @@ int main() {
|
|||||||
std::atomic<size_t> index4{0};
|
std::atomic<size_t> index4{0};
|
||||||
auto job4 = [&p4, &index4, &lead_spinner]() {
|
auto job4 = [&p4, &index4, &lead_spinner]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
p4.set_prefix_text("{ " + std::to_string(p4.current()) + "% } ");
|
p4.set_prefix_text(" { " + std::to_string(p4.current()) + "% } ");
|
||||||
p4.lead_bar_progress_with(lead_spinner[index4 % lead_spinner.size()]);
|
p4.lead_bar_progress_with(lead_spinner[index4 % lead_spinner.size()]);
|
||||||
index4 += 1;
|
index4 += 1;
|
||||||
if (p4.current() + 2 >= 100) {
|
if (p4.current() + 2 >= 100) {
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
p4.set_foreground_color(indica::Color::RED);
|
p4.set_foreground_color(indica::Color::RED);
|
||||||
p4.set_prefix_text("{ ERROR }");
|
p4.set_prefix_text(" { ERROR }");
|
||||||
p4.start_bar_with("");
|
p4.start_bar_with("");
|
||||||
p4.fill_bar_progress_with("");
|
p4.fill_bar_progress_with("");
|
||||||
p4.lead_bar_progress_with("");
|
p4.lead_bar_progress_with("");
|
||||||
@@ -190,7 +193,7 @@ int main() {
|
|||||||
//
|
//
|
||||||
indica::ProgressBar p;
|
indica::ProgressBar p;
|
||||||
p.set_bar_width(50);
|
p.set_bar_width(50);
|
||||||
p.start_bar_with("[");
|
p.start_bar_with(" [");
|
||||||
p.fill_bar_progress_with("■");
|
p.fill_bar_progress_with("■");
|
||||||
p.lead_bar_progress_with("■");
|
p.lead_bar_progress_with("■");
|
||||||
p.fill_bar_remainder_with("-");
|
p.fill_bar_remainder_with("-");
|
||||||
@@ -217,6 +220,7 @@ int main() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
indica::ProgressSpinner p;
|
indica::ProgressSpinner p;
|
||||||
|
p.set_prefix_text(" ");
|
||||||
p.set_postfix_text("Checking credentials");
|
p.set_postfix_text("Checking credentials");
|
||||||
p.set_foreground_color(indica::Color::YELLOW);
|
p.set_foreground_color(indica::Color::YELLOW);
|
||||||
p.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"});
|
p.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"});
|
||||||
@@ -224,14 +228,13 @@ int main() {
|
|||||||
while (true) {
|
while (true) {
|
||||||
if (p.is_completed()) {
|
if (p.is_completed()) {
|
||||||
p.set_foreground_color(indica::Color::GREEN);
|
p.set_foreground_color(indica::Color::GREEN);
|
||||||
p.set_prefix_text("✔");
|
p.set_prefix_text(" ✔");
|
||||||
p.hide_spinner();
|
p.hide_spinner();
|
||||||
p.hide_percentage();
|
p.hide_percentage();
|
||||||
p.set_postfix_text("Authenticated!");
|
p.set_postfix_text("Authenticated!");
|
||||||
p.mark_as_completed();
|
p.mark_as_completed();
|
||||||
break;
|
break;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
p.tick();
|
p.tick();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
||||||
}
|
}
|
||||||
@@ -240,7 +243,7 @@ int main() {
|
|||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Compiling mission\n";
|
std::cout << " Compiling mission\n";
|
||||||
{
|
{
|
||||||
indica::ProgressSpinner p;
|
indica::ProgressSpinner p;
|
||||||
p.set_prefix_text(" - ");
|
p.set_prefix_text(" - ");
|
||||||
@@ -254,38 +257,31 @@ int main() {
|
|||||||
if (current == 24) {
|
if (current == 24) {
|
||||||
p.set_prefix_text(" - ✔");
|
p.set_prefix_text(" - ✔");
|
||||||
p.hide_spinner();
|
p.hide_spinner();
|
||||||
}
|
} else if (current == 25) {
|
||||||
else if (current == 25) {
|
std::cout << std::endl;
|
||||||
|
p.show_spinner();
|
||||||
|
p.set_prefix_text(" - ");
|
||||||
|
p.set_postfix_text("Contacting Kerbal headquarters");
|
||||||
|
} else if (current == 49) {
|
||||||
|
p.set_prefix_text(" - ✔");
|
||||||
|
p.hide_spinner();
|
||||||
|
} else if (current == 50) {
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
p.show_spinner();
|
p.show_spinner();
|
||||||
p.set_prefix_text(" - ");
|
p.set_prefix_text(" - ");
|
||||||
p.set_postfix_text("Designing spaceship");
|
p.set_postfix_text("Designing spaceship");
|
||||||
}
|
} else if (current == 74) {
|
||||||
else if (current == 49) {
|
|
||||||
p.set_prefix_text(" - ✔");
|
p.set_prefix_text(" - ✔");
|
||||||
p.hide_spinner();
|
p.hide_spinner();
|
||||||
}
|
} else if (current == 75) {
|
||||||
else if (current == 50) {
|
|
||||||
std::cout << std::endl;
|
|
||||||
p.show_spinner();
|
|
||||||
p.set_prefix_text(" - ");
|
|
||||||
p.set_postfix_text("Contacting Elon Musk");
|
|
||||||
}
|
|
||||||
else if (current == 74) {
|
|
||||||
p.set_prefix_text(" - ✔");
|
|
||||||
p.hide_spinner();
|
|
||||||
}
|
|
||||||
else if (current == 75) {
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
p.show_spinner();
|
p.show_spinner();
|
||||||
p.set_prefix_text(" - ");
|
p.set_prefix_text(" - ");
|
||||||
p.set_postfix_text("Launching rocket");
|
p.set_postfix_text("Launching rocket");
|
||||||
}
|
} else if (current == 95) {
|
||||||
else if (current == 95) {
|
|
||||||
p.set_prefix_text(" - ✔");
|
p.set_prefix_text(" - ✔");
|
||||||
p.hide_spinner();
|
p.hide_spinner();
|
||||||
}
|
} else if (current == 99) {
|
||||||
else if (current == 99) {
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
//
|
//
|
||||||
// NESTED PROGRESS BAR
|
// NESTED PROGRESS BAR
|
||||||
@@ -295,12 +291,14 @@ int main() {
|
|||||||
p2.set_prefix_text(" - ");
|
p2.set_prefix_text(" - ");
|
||||||
p2.start_bar_with("[🌎");
|
p2.start_bar_with("[🌎");
|
||||||
p2.fill_bar_progress_with(" ");
|
p2.fill_bar_progress_with(" ");
|
||||||
p2.lead_bar_progress_with("🚀");
|
p2.lead_bar_progress_with("⠁⠂⠄🚀");
|
||||||
p2.fill_bar_remainder_with(" ");
|
p2.fill_bar_remainder_with(" ");
|
||||||
p2.end_bar_with("🌑]");
|
p2.end_bar_with("🌑]");
|
||||||
p2.set_postfix_text("Achieved low-Earth orbit");
|
p2.set_postfix_text("Achieved low-Earth orbit");
|
||||||
p2.set_foreground_color(indica::Color::WHITE);
|
p2.set_foreground_color(indica::Color::WHITE);
|
||||||
auto job2 = [&p2]() {
|
std::vector<std::string> ship_trail{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"};
|
||||||
|
std::atomic<int> ship_trail_index{0};
|
||||||
|
auto job2 = [&p2, &ship_trail_index, &ship_trail]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
auto ticks = p2.current();
|
auto ticks = p2.current();
|
||||||
if (ticks > 20 && ticks < 50)
|
if (ticks > 20 && ticks < 50)
|
||||||
@@ -311,7 +309,14 @@ int main() {
|
|||||||
p2.set_postfix_text("Almost there");
|
p2.set_postfix_text("Almost there");
|
||||||
else if (ticks >= 98)
|
else if (ticks >= 98)
|
||||||
p2.set_postfix_text("Landed on the Moon");
|
p2.set_postfix_text("Landed on the Moon");
|
||||||
|
p2.lead_bar_progress_with(
|
||||||
|
ship_trail[(ship_trail_index - 3) % ship_trail.size()] +
|
||||||
|
ship_trail[(ship_trail_index - 2) % ship_trail.size()] +
|
||||||
|
ship_trail[(ship_trail_index - 1) % ship_trail.size()] +
|
||||||
|
ship_trail[ship_trail_index % ship_trail.size()] +
|
||||||
|
"🚀");
|
||||||
p2.tick();
|
p2.tick();
|
||||||
|
ship_trail_index += 1;
|
||||||
if (p2.is_completed())
|
if (p2.is_completed())
|
||||||
break;
|
break;
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(80));
|
std::this_thread::sleep_for(std::chrono::milliseconds(80));
|
||||||
@@ -337,6 +342,7 @@ int main() {
|
|||||||
|
|
||||||
// Show cursor
|
// Show cursor
|
||||||
std::cout << "\e[?25h";
|
std::cout << "\e[?25h";
|
||||||
|
std::cout << "\n\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user