mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Updated samples/demos to show usage of hide/show time elapsed/remaining
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
#include <chrono>
|
||||
#include <indicators/block_progress_bar.hpp>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
int main() {
|
||||
|
||||
// Hide cursor
|
||||
std::cout << "\e[?25l";
|
||||
|
||||
|
||||
indicators::BlockProgressBar bar;
|
||||
|
||||
|
||||
// Configure the bar
|
||||
bar.set_bar_width(80);
|
||||
bar.start_bar_with("[");
|
||||
bar.end_bar_with("]");
|
||||
bar.set_foreground_color(indicators::Color::WHITE);
|
||||
|
||||
bar.set_foreground_color(indicators::Color::WHITE);
|
||||
bar.hide_elapsed_time();
|
||||
bar.hide_remaining_time();
|
||||
|
||||
// Update bar state
|
||||
auto progress = 0.0f;
|
||||
while (true) {
|
||||
@@ -26,7 +28,7 @@ int main() {
|
||||
}
|
||||
|
||||
// Show cursor
|
||||
std::cout << "\e[?25h";
|
||||
std::cout << "\e[?25h";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -11,31 +11,30 @@ int main() {
|
||||
bar.fill_bar_remainder_with("-");
|
||||
bar.end_bar_with("]");
|
||||
bar.set_foreground_color(indicators::Color::YELLOW);
|
||||
bar.hide_elapsed_time();
|
||||
bar.hide_remaining_time();
|
||||
|
||||
// As configured, the bar will look like this:
|
||||
//
|
||||
// [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■-------------] 70%
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
std::atomic<size_t> index{0};
|
||||
std::vector<std::string> status_text =
|
||||
{
|
||||
"Rocket.exe is not responding",
|
||||
"Finding a replacement engineer",
|
||||
"Buying more snacks",
|
||||
"Assimilating the modding community",
|
||||
"Crossing fingers",
|
||||
"Porting KSP to a Nokia 3310"
|
||||
};
|
||||
|
||||
std::vector<std::string> status_text = {"Rocket.exe is not responding",
|
||||
"Finding a replacement engineer",
|
||||
"Buying more snacks",
|
||||
"Assimilating the modding community",
|
||||
"Crossing fingers",
|
||||
"Porting KSP to a Nokia 3310"};
|
||||
|
||||
// Let's say you want to append some status text to the right of the progress bar
|
||||
// You can use bar.set_postfix_text(...) to append text to the right
|
||||
//
|
||||
// [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■-------------] 70% Finding a replacement engineer
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
auto job = [&bar, &index, &status_text]() {
|
||||
while (true) {
|
||||
@@ -58,6 +57,6 @@ int main() {
|
||||
second_job.join();
|
||||
third_job.join();
|
||||
last_job.join();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <chrono>
|
||||
#include <indicators/progress_bar.hpp>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
int main() {
|
||||
indicators::ProgressBar bar;
|
||||
|
||||
|
||||
// Configure the bar
|
||||
bar.set_bar_width(50);
|
||||
bar.start_bar_with("[");
|
||||
@@ -13,26 +13,28 @@ int main() {
|
||||
bar.fill_bar_remainder_with(" ");
|
||||
bar.end_bar_with("]");
|
||||
bar.set_postfix_text("Getting started");
|
||||
bar.set_foreground_color(indicators::Color::GREEN);
|
||||
|
||||
bar.set_foreground_color(indicators::Color::GREEN);
|
||||
bar.hide_elapsed_time();
|
||||
bar.hide_remaining_time();
|
||||
|
||||
// Update bar state
|
||||
|
||||
|
||||
bar.set_progress(10); // 10% done
|
||||
|
||||
|
||||
// do some work
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
|
||||
bar.set_progress(30); // 30% done
|
||||
|
||||
// do some more work
|
||||
|
||||
// do some more work
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(600));
|
||||
|
||||
|
||||
bar.set_progress(65); // 65% done
|
||||
|
||||
|
||||
// do final bit of work
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
|
||||
|
||||
bar.set_progress(100); // all done
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <chrono>
|
||||
#include <indicators/progress_bar.hpp>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
int main() {
|
||||
indicators::ProgressBar bar;
|
||||
|
||||
|
||||
// Configure the bar
|
||||
bar.set_bar_width(50);
|
||||
bar.start_bar_with("[");
|
||||
@@ -13,8 +13,10 @@ int main() {
|
||||
bar.fill_bar_remainder_with(" ");
|
||||
bar.end_bar_with("]");
|
||||
bar.set_postfix_text("Getting started");
|
||||
bar.set_foreground_color(indicators::Color::GREEN);
|
||||
|
||||
bar.set_foreground_color(indicators::Color::GREEN);
|
||||
bar.hide_elapsed_time();
|
||||
bar.hide_remaining_time();
|
||||
|
||||
// Update bar state
|
||||
while (true) {
|
||||
bar.tick();
|
||||
|
||||
@@ -6,12 +6,14 @@ int main() {
|
||||
std::cout << "\e[?25l";
|
||||
|
||||
indicators::ProgressSpinner spinner;
|
||||
|
||||
|
||||
// Configure the spinner
|
||||
spinner.set_postfix_text("Checking credentials");
|
||||
spinner.set_foreground_color(indicators::Color::YELLOW);
|
||||
spinner.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"});
|
||||
|
||||
spinner.hide_elapsed_time();
|
||||
spinner.hide_remaining_time();
|
||||
|
||||
// Update spinner state
|
||||
auto job = [&spinner]() {
|
||||
while (true) {
|
||||
@@ -32,7 +34,7 @@ int main() {
|
||||
thread.join();
|
||||
|
||||
// Show cursor
|
||||
std::cout << "\e[?25h";
|
||||
std::cout << "\e[?25h";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user