mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Added dynamic progress GIFs
This commit is contained in:
BIN
img/dynamic_progress_bar.gif
Normal file
BIN
img/dynamic_progress_bar.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 MiB |
BIN
img/dynamic_progress_bar_hide_completed.gif
Normal file
BIN
img/dynamic_progress_bar_hide_completed.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.1 MiB |
@@ -44,6 +44,7 @@ public:
|
||||
for (auto &bar : bars_) {
|
||||
bar.get().multi_progress_mode_ = true;
|
||||
++total_count_;
|
||||
++incomplete_count_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,21 +102,21 @@ private:
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
auto &hide_bar_when_complete = get_value<details::ProgressBarOption::hide_bar_when_complete>();
|
||||
if (hide_bar_when_complete) {
|
||||
// incomplete_count_ = 0;
|
||||
// for (auto &bar : bars_)
|
||||
// if (!bar.get().is_completed())
|
||||
// incomplete_count_ += 1;
|
||||
// if (started_) {
|
||||
// for (size_t i = 0; i < incomplete_count_; ++i)
|
||||
// std::cout << "\e[A"
|
||||
// << "\r\e[K" << std::flush;
|
||||
// }
|
||||
// for (auto &bar : bars_) {
|
||||
// if (!bar.get().is_completed()) {
|
||||
// bar.get().print_progress(true);
|
||||
// std::cout << "\n";
|
||||
// }
|
||||
// }
|
||||
// Hide completed bars
|
||||
if (started_) {
|
||||
for (size_t i = 0; i < incomplete_count_; ++i)
|
||||
std::cout << "\033[A\r\033[K" << std::flush;
|
||||
}
|
||||
incomplete_count_ = 0;
|
||||
for (auto &bar : bars_) {
|
||||
if (!bar.get().is_completed()) {
|
||||
bar.get().print_progress(true);
|
||||
std::cout << "\n";
|
||||
++incomplete_count_;
|
||||
}
|
||||
}
|
||||
if (!started_)
|
||||
started_ = true;
|
||||
} else {
|
||||
// Don't hide any bars
|
||||
if (started_) {
|
||||
|
||||
@@ -6,29 +6,29 @@ int main() {
|
||||
|
||||
ProgressBar bar1{option::BarWidth{50}, option::ForegroundColor{Color::red},
|
||||
option::ShowElapsedTime{true}, option::ShowRemainingTime{true},
|
||||
option::PrefixText{"5c90d4a2d1a8: Downloading "}};
|
||||
option::PrefixText{" 5c90d4a2d1a8: Downloading "}};
|
||||
|
||||
ProgressBar bar2{option::BarWidth{50}, option::ForegroundColor{Color::yellow},
|
||||
option::ShowElapsedTime{true}, option::ShowRemainingTime{true},
|
||||
option::PrefixText{"22337bfd13a9: Downloading "}};
|
||||
option::PrefixText{" 22337bfd13a9: Downloading "}};
|
||||
|
||||
ProgressBar bar3{option::BarWidth{50}, option::ForegroundColor{Color::green},
|
||||
option::ShowElapsedTime{true}, option::ShowRemainingTime{true},
|
||||
option::PrefixText{"10f26c680a34: Downloading "}};
|
||||
option::PrefixText{" 10f26c680a34: Downloading "}};
|
||||
|
||||
ProgressBar bar4{option::BarWidth{50}, option::ForegroundColor{Color::white},
|
||||
option::ShowElapsedTime{true}, option::ShowRemainingTime{true},
|
||||
option::PrefixText{"6364e0d7a283: Downloading "}};
|
||||
option::PrefixText{" 6364e0d7a283: Downloading "}};
|
||||
|
||||
ProgressBar bar5{option::BarWidth{50}, option::ForegroundColor{Color::blue},
|
||||
option::ShowElapsedTime{true}, option::ShowRemainingTime{true},
|
||||
option::PrefixText{"ff1356ba118b: Downloading "}};
|
||||
option::PrefixText{" ff1356ba118b: Downloading "}};
|
||||
|
||||
ProgressBar bar6{option::BarWidth{50}, option::ForegroundColor{Color::yellow},
|
||||
ProgressBar bar6{option::BarWidth{50}, option::ForegroundColor{Color::cyan},
|
||||
option::ShowElapsedTime{true}, option::ShowRemainingTime{true},
|
||||
option::PrefixText{"5a17453338b4: Downloading "}};
|
||||
option::PrefixText{" 5a17453338b4: Downloading "}};
|
||||
|
||||
// std::cout << termcolor::bold << termcolor::white << "Pulling image foo:bar/baz\n";
|
||||
std::cout << termcolor::bold << termcolor::white << "\n\n Pulling image foo:bar/baz\n";
|
||||
|
||||
DynamicProgress<ProgressBar> bars(bar1, bar2, bar3);
|
||||
bars.set_option(option::HideBarWhenComplete{false});
|
||||
@@ -38,8 +38,11 @@ int main() {
|
||||
auto job4 = [&bars](size_t i) {
|
||||
while (true) {
|
||||
bars[i].tick();
|
||||
if (bars[i].is_completed())
|
||||
if (bars[i].is_completed()) {
|
||||
bars[i].set_option(option::PrefixText{" 6364e0d7a283: Pull complete "});
|
||||
bars[i].mark_as_completed();
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
}
|
||||
};
|
||||
@@ -47,17 +50,23 @@ int main() {
|
||||
auto job5 = [&bars](size_t i) {
|
||||
while (true) {
|
||||
bars[i].tick();
|
||||
if (bars[i].is_completed())
|
||||
if (bars[i].is_completed()) {
|
||||
bars[i].set_option(option::PrefixText{" ff1356ba118b: Pull complete "});
|
||||
bars[i].mark_as_completed();
|
||||
break;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(75));
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
};
|
||||
|
||||
auto job6 = [&bars](size_t i) {
|
||||
while (true) {
|
||||
bars[i].tick();
|
||||
if (bars[i].is_completed())
|
||||
if (bars[i].is_completed()) {
|
||||
bars[i].set_option(option::PrefixText{" 5a17453338b4: Pull complete "});
|
||||
bars[i].mark_as_completed();
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
||||
}
|
||||
};
|
||||
@@ -66,6 +75,7 @@ int main() {
|
||||
while (true) {
|
||||
bars[0].tick();
|
||||
if (bars[0].is_completed()) {
|
||||
bars[0].set_option(option::PrefixText{" 5c90d4a2d1a8: Pull complete "});
|
||||
// bar1 is completed, adding bar6
|
||||
auto i = bars.push_back(bar6);
|
||||
sixth_job = std::thread(job6, i);
|
||||
@@ -80,6 +90,7 @@ int main() {
|
||||
while (true) {
|
||||
bars[1].tick();
|
||||
if (bars[1].is_completed()) {
|
||||
bars[1].set_option(option::PrefixText{" 22337bfd13a9: Pull complete "});
|
||||
// bar2 is completed, adding bar5
|
||||
auto i = bars.push_back(bar5);
|
||||
fifth_job = std::thread(job5, i);
|
||||
@@ -94,6 +105,7 @@ int main() {
|
||||
while (true) {
|
||||
bars[2].tick();
|
||||
if (bars[2].is_completed()) {
|
||||
bars[2].set_option(option::PrefixText{" 10f26c680a34: Pull complete "});
|
||||
// bar3 is completed, adding bar4
|
||||
auto i = bars.push_back(bar4);
|
||||
fourth_job = std::thread(job4, i);
|
||||
@@ -112,9 +124,8 @@ int main() {
|
||||
second_job.join();
|
||||
first_job.join();
|
||||
|
||||
// std::cout << termcolor::bold << termcolor::yellow << "\r✔ Downloaded image foo/bar:baz" << std::endl;
|
||||
|
||||
// std::cout << termcolor::reset;
|
||||
std::cout << termcolor::bold << termcolor::green << " ✔ Downloaded image foo/bar:baz\n\n\n\n" << std::endl;
|
||||
std::cout << termcolor::reset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user