Formatted sample

This commit is contained in:
Pranav Srinivas Kumar
2019-12-04 09:40:09 -06:00
parent 30226da135
commit 36d122fa17

View File

@@ -15,33 +15,30 @@ int main() {
p1.fill_progress_with(""); p1.fill_progress_with("");
p1.lead_progress_with(""); p1.lead_progress_with("");
p1.fill_remainder_with(" "); p1.fill_remainder_with(" ");
p1.end_with("]"); p1.end_with("]");
p1.color(ProgressBar::Color::YELLOW); p1.color(ProgressBar::Color::YELLOW);
std::atomic<size_t> index1{0}; std::atomic<size_t> index1{0};
std::vector<std::string> status_text1 = std::vector<std::string> status_text1 = {"Rocket.exe is not responding",
{ "Buying more snacks",
"Rocket.exe is not responding", "Finding a replacement engineer",
"Buying more snacks", "Assimilating the modding community",
"Finding a replacement engineer", "Crossing fingers",
"Assimilating the modding community", "Porting KSP to a Nokia 3310",
"Crossing fingers", "Flexing struts",
"Porting KSP to a Nokia 3310", "Releasing space whales",
"Flexing struts", "Watching paint dry"};
"Releasing space whales",
"Watching paint dry"
};
auto job1 = [&p1, &index1, &status_text1]() { auto job1 = [&p1, &index1, &status_text1]() {
while (true) { while (true) {
if (p1.completed()) if (p1.completed())
break; break;
p1.set_status_text(status_text1[index1 % status_text1.size()]); p1.set_status_text(status_text1[index1 % status_text1.size()]);
p1.set_progress(index1 * 10); p1.set_progress(index1 * 10);
index1 += 1; index1 += 1;
std::this_thread::sleep_for(std::chrono::milliseconds(600)); std::this_thread::sleep_for(std::chrono::milliseconds(600));
} }
}; };
std::thread thread1(job1); std::thread thread1(job1);
thread1.join(); thread1.join();
@@ -58,18 +55,19 @@ int main() {
p3.color(ProgressBar::Color::WHITE); p3.color(ProgressBar::Color::WHITE);
p3.show_percentage(false); p3.show_percentage(false);
auto job3 = [&p3]() { auto job3 = [&p3]() {
while (true) { while (true) {
p3.start_with("Reading package list... " + std::to_string(p3.current()) + "% "); p3.start_with("Reading package list... " + std::to_string(p3.current()) +
if (p3.current() + 2 >= 100) "% ");
p3.start_with("Reading package list... Done"); if (p3.current() + 2 >= 100)
p3.tick(); p3.start_with("Reading package list... Done");
if (p3.completed()) { p3.tick();
break; if (p3.completed()) {
} break;
std::this_thread::sleep_for(std::chrono::milliseconds(25)); }
} std::this_thread::sleep_for(std::chrono::milliseconds(25));
}; }
std::thread thread3(job3); };
std::thread thread3(job3);
thread3.join(); thread3.join();
// //
@@ -85,23 +83,23 @@ int main() {
p2.set_status_text("Getting started"); p2.set_status_text("Getting started");
p2.color(ProgressBar::Color::GREEN); p2.color(ProgressBar::Color::GREEN);
auto job2 = [&p2]() { auto job2 = [&p2]() {
while (true) { while (true) {
auto ticks = p2.current(); auto ticks = p2.current();
if (ticks > 20 && ticks < 50) if (ticks > 20 && ticks < 50)
p2.set_status_text("Delaying the inevitable"); p2.set_status_text("Delaying the inevitable");
else if (ticks > 50 && ticks < 80) else if (ticks > 50 && ticks < 80)
p2.set_status_text("Crying quietly"); p2.set_status_text("Crying quietly");
else if (ticks > 80 && ticks < 98) else if (ticks > 80 && ticks < 98)
p2.set_status_text("Almost there"); p2.set_status_text("Almost there");
else if (ticks >= 98) else if (ticks >= 98)
p2.set_status_text("Done"); p2.set_status_text("Done");
p2.tick(); p2.tick();
if (p2.completed()) if (p2.completed())
break; break;
std::this_thread::sleep_for(std::chrono::milliseconds(30)); std::this_thread::sleep_for(std::chrono::milliseconds(30));
} }
}; };
std::thread thread2(job2); std::thread thread2(job2);
thread2.join(); thread2.join();
// //
@@ -111,59 +109,60 @@ int main() {
p5.bar_width(100); p5.bar_width(100);
p5.start_with("🌏"); p5.start_with("🌏");
p5.fill_progress_with("·"); p5.fill_progress_with("·");
p5.lead_progress_with("🛸"); p5.lead_progress_with("🛸");
p5.fill_remainder_with(" "); p5.fill_remainder_with(" ");
p5.end_with("🌑"); p5.end_with("🌑");
p5.show_percentage(true); p5.show_percentage(true);
p5.color(ProgressBar::Color::WHITE); p5.color(ProgressBar::Color::WHITE);
auto job5 = [&p5]() { auto job5 = [&p5]() {
while (true) { while (true) {
if (p5.current() % 5 == 0) { if (p5.current() % 5 == 0) {
p5.fill_progress_with("·"); p5.fill_progress_with("·");
} else { } else {
p5.fill_progress_with(" "); p5.fill_progress_with(" ");
} }
p5.tick(); p5.tick();
if (p5.completed()) { if (p5.completed()) {
break; break;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(75)); std::this_thread::sleep_for(std::chrono::milliseconds(75));
} }
}; };
std::thread thread5(job5); std::thread thread5(job5);
thread5.join(); thread5.join();
// //
// PROGRESS BAR 4 // PROGRESS BAR 4
// //
std::vector<std::string> lead_spinner{"", "", "", "", "", "", "", "", "", ""}; std::vector<std::string> lead_spinner{"", "", "", "", "",
"", "", "", "", ""};
ProgressBar p4; ProgressBar p4;
p4.bar_width(50); p4.bar_width(50);
p4.start_with("["); p4.start_with("[");
p4.fill_progress_with(""); p4.fill_progress_with("");
p4.lead_progress_with(""); p4.lead_progress_with("");
p4.fill_remainder_with(" "); p4.fill_remainder_with(" ");
p4.end_with(" ]"); p4.end_with(" ]");
p4.color(ProgressBar::Color::CYAN); p4.color(ProgressBar::Color::CYAN);
p4.set_status_text("Restoring system state"); p4.set_status_text("Restoring system state");
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.lead_progress_with(lead_spinner[index4 % lead_spinner.size()]); p4.lead_progress_with(lead_spinner[index4 % lead_spinner.size()]);
index4 += 1; index4 += 1;
if (p4.current() + 2 >= 100) if (p4.current() + 2 >= 100)
p4.set_status_text("State restored to Restore_Point_1241531"); p4.set_status_text("State restored to Restore_Point_1241531");
p4.tick(); p4.tick();
if (p4.completed()) { if (p4.completed()) {
break; break;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(50)); std::this_thread::sleep_for(std::chrono::milliseconds(50));
} }
}; };
std::thread thread4(job4); std::thread thread4(job4);
thread4.join(); thread4.join();
std::this_thread::sleep_for(std::chrono::milliseconds(5000)); std::this_thread::sleep_for(std::chrono::milliseconds(5000));
// Show cursor // Show cursor
std::cout << "\e[?25h"; std::cout << "\e[?25h";