mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Update README.md
This commit is contained in:
52
README.md
52
README.md
@@ -6,9 +6,13 @@
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
#include <progress/bar.hpp>
|
#include <progress/bar.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
ProgressBar bar;
|
ProgressBar bar;
|
||||||
|
|
||||||
|
// Configure progress bar
|
||||||
bar.bar_width(50);
|
bar.bar_width(50);
|
||||||
bar.start_with("[");
|
bar.start_with("[");
|
||||||
bar.fill_progress_with("■");
|
bar.fill_progress_with("■");
|
||||||
@@ -23,24 +27,40 @@ int main() {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
auto job = [&bar]() {
|
std::atomic<size_t> index{0};
|
||||||
while(true) {
|
std::vector<std::string> status_text =
|
||||||
if (bar.completed())
|
{
|
||||||
break;
|
"Rocket.exe is not responding",
|
||||||
bar.tick();
|
"Finding a replacement engineer",
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
"Buying more snacks",
|
||||||
}
|
"Assimilating the modding community",
|
||||||
};
|
"Crossing fingers",
|
||||||
|
"Porting KSP to a Nokia 3310"
|
||||||
|
};
|
||||||
|
|
||||||
std::thread first_thread(job);
|
auto job = [&bar, &index, &status_text]() {
|
||||||
std::thread second_thread(job);
|
while (true) {
|
||||||
std::thread third_thread(job);
|
if (bar.completed()) {
|
||||||
std::thread last_thread(job);
|
break;
|
||||||
|
}
|
||||||
|
bar.append_text(status_text[index % status_text.size()]);
|
||||||
|
bar.tick();
|
||||||
|
index += 1;
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
first_thread.join();
|
std::thread first_job(job);
|
||||||
second_thread.join();
|
std::thread second_job(job);
|
||||||
third_thread.join();
|
std::thread third_job(job);
|
||||||
last_thread.join();
|
std::thread last_job(job);
|
||||||
|
|
||||||
|
first_job.join();
|
||||||
|
second_job.join();
|
||||||
|
third_job.join();
|
||||||
|
last_job.join();
|
||||||
|
|
||||||
|
std::cout << "Done\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user