mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-11 00:55:27 +08:00
Updated multiple bars sample
This commit is contained in:
@@ -57,12 +57,7 @@ public:
|
||||
void set_progress(float value) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lock{_mutex};
|
||||
if (_completed)
|
||||
return;
|
||||
_progress = value;
|
||||
if (_progress >= 100.0) {
|
||||
_completed = true;
|
||||
}
|
||||
}
|
||||
_print_progress();
|
||||
}
|
||||
@@ -70,12 +65,7 @@ public:
|
||||
void tick() {
|
||||
{
|
||||
std::unique_lock<std::mutex> lock{_mutex};
|
||||
if (_completed)
|
||||
return;
|
||||
_progress += 1;
|
||||
if (_progress >= 100.0) {
|
||||
_completed = true;
|
||||
}
|
||||
}
|
||||
_print_progress();
|
||||
}
|
||||
@@ -146,8 +136,12 @@ private:
|
||||
if (_show_percentage) {
|
||||
std::cout << " " << std::min(static_cast<size_t>(_progress), size_t(100)) << "%";
|
||||
}
|
||||
if (_max_text_after_length == 0) _max_text_after_length = 20;
|
||||
std::cout << " " << _text_after << std::string(_max_text_after_length, ' ') << "\r";
|
||||
std::cout.flush();
|
||||
if (_progress > 100.0) {
|
||||
_completed = true;
|
||||
}
|
||||
if (_completed)
|
||||
std::cout << termcolor::reset << std::endl;
|
||||
}
|
||||
|
||||
@@ -47,13 +47,12 @@ int main() {
|
||||
//
|
||||
ProgressBar p2;
|
||||
p2.bar_width(50);
|
||||
p2.start_with("[");
|
||||
p2.start_with("Getting started [");
|
||||
p2.fill_progress_with("#");
|
||||
p2.lead_progress_with("#");
|
||||
p2.fill_remainder_with(" ");
|
||||
p2.end_with("]");
|
||||
p2.color(ProgressBar::Color::GREEN);
|
||||
p2.append_text("Getting started");
|
||||
auto job2 = [&p2]() {
|
||||
while (true) {
|
||||
if (p2.completed())
|
||||
@@ -61,13 +60,13 @@ int main() {
|
||||
p2.tick();
|
||||
auto ticks = p2.current();
|
||||
if (ticks > 20 && ticks < 50)
|
||||
p2.append_text("Calling Lionel Messi");
|
||||
p2.start_with("Delaying the inevitable [");
|
||||
else if (ticks > 50 && ticks < 80)
|
||||
p2.append_text("Crying quietly");
|
||||
p2.start_with("Crying quietly [");
|
||||
else if (ticks > 80)
|
||||
p2.append_text("Almost there");
|
||||
p2.start_with("Almost there [");
|
||||
else if (ticks > 98)
|
||||
p2.append_text("Done");
|
||||
p2.start_with("Done [");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
};
|
||||
@@ -91,6 +90,7 @@ int main() {
|
||||
p3.start_with("Downloading the Sun " + std::to_string(p3.current()) + "% ");
|
||||
p3.tick();
|
||||
if (p3.completed()) {
|
||||
p3.start_with("Downloading the Sun 100%");
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
|
||||
Reference in New Issue
Block a user