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,2 +1,2 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
find ./include ./demo/ -type f \( -iname \*.cpp -o -iname \*.hpp \) | xargs clang-format -style="{ColumnLimit : 100}" -i
|
find ./include ./demo/ ./samples/ -type f \( -iname \*.cpp -o -iname \*.hpp \) | xargs clang-format -style="{ColumnLimit : 100}" -i
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ int main() {
|
|||||||
p.lead_bar_progress_with("■");
|
p.lead_bar_progress_with("■");
|
||||||
p.fill_bar_remainder_with(" ");
|
p.fill_bar_remainder_with(" ");
|
||||||
p.end_bar_with(" ]");
|
p.end_bar_with(" ]");
|
||||||
|
p.hide_elapsed_time();
|
||||||
|
p.hide_remaining_time();
|
||||||
p.set_foreground_color(indicators::Color::YELLOW);
|
p.set_foreground_color(indicators::Color::YELLOW);
|
||||||
|
|
||||||
std::atomic<size_t> index{0};
|
std::atomic<size_t> index{0};
|
||||||
@@ -57,6 +59,8 @@ int main() {
|
|||||||
p.lead_bar_progress_with("");
|
p.lead_bar_progress_with("");
|
||||||
p.fill_bar_remainder_with("");
|
p.fill_bar_remainder_with("");
|
||||||
p.end_bar_with("");
|
p.end_bar_with("");
|
||||||
|
p.hide_elapsed_time();
|
||||||
|
p.hide_remaining_time();
|
||||||
p.set_foreground_color(indicators::Color::WHITE);
|
p.set_foreground_color(indicators::Color::WHITE);
|
||||||
p.hide_percentage();
|
p.hide_percentage();
|
||||||
auto job = [&p]() {
|
auto job = [&p]() {
|
||||||
@@ -87,6 +91,8 @@ int main() {
|
|||||||
p.fill_bar_remainder_with(" ");
|
p.fill_bar_remainder_with(" ");
|
||||||
p.end_bar_with("]");
|
p.end_bar_with("]");
|
||||||
p.set_postfix_text("Getting started");
|
p.set_postfix_text("Getting started");
|
||||||
|
p.hide_elapsed_time();
|
||||||
|
p.hide_remaining_time();
|
||||||
p.set_foreground_color(indicators::Color::GREEN);
|
p.set_foreground_color(indicators::Color::GREEN);
|
||||||
auto job = [&p]() {
|
auto job = [&p]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -124,6 +130,8 @@ int main() {
|
|||||||
p4.set_foreground_color(indicators::Color::CYAN);
|
p4.set_foreground_color(indicators::Color::CYAN);
|
||||||
p4.set_postfix_text("Restoring system state");
|
p4.set_postfix_text("Restoring system state");
|
||||||
p4.hide_percentage();
|
p4.hide_percentage();
|
||||||
|
p4.hide_elapsed_time();
|
||||||
|
p4.hide_remaining_time();
|
||||||
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) {
|
||||||
@@ -167,6 +175,8 @@ int main() {
|
|||||||
p.set_progress(100);
|
p.set_progress(100);
|
||||||
p.set_foreground_color(indicators::Color::WHITE);
|
p.set_foreground_color(indicators::Color::WHITE);
|
||||||
p.set_postfix_text("Reverting system restore");
|
p.set_postfix_text("Reverting system restore");
|
||||||
|
p.hide_elapsed_time();
|
||||||
|
p.hide_remaining_time();
|
||||||
std::atomic<size_t> progress{100};
|
std::atomic<size_t> progress{100};
|
||||||
auto job = [&p, &progress]() {
|
auto job = [&p, &progress]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -194,6 +204,8 @@ int main() {
|
|||||||
p.set_postfix_text("Checking credentials");
|
p.set_postfix_text("Checking credentials");
|
||||||
p.set_foreground_color(indicators::Color::YELLOW);
|
p.set_foreground_color(indicators::Color::YELLOW);
|
||||||
p.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"});
|
p.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"});
|
||||||
|
p.hide_elapsed_time();
|
||||||
|
p.hide_remaining_time();
|
||||||
auto job = [&p]() {
|
auto job = [&p]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (p.is_completed()) {
|
if (p.is_completed()) {
|
||||||
@@ -224,6 +236,8 @@ int main() {
|
|||||||
p.set_foreground_color(indicators::Color::WHITE);
|
p.set_foreground_color(indicators::Color::WHITE);
|
||||||
p.set_spinner_states({"▖", "▘", "▝", "▗"});
|
p.set_spinner_states({"▖", "▘", "▝", "▗"});
|
||||||
p.hide_percentage();
|
p.hide_percentage();
|
||||||
|
p.hide_elapsed_time();
|
||||||
|
p.hide_remaining_time();
|
||||||
auto job = [&p]() {
|
auto job = [&p]() {
|
||||||
while (true) {
|
while (true) {
|
||||||
auto current = p.current();
|
auto current = p.current();
|
||||||
@@ -269,6 +283,8 @@ int main() {
|
|||||||
p2.end_bar_with("🌑");
|
p2.end_bar_with("🌑");
|
||||||
p2.set_postfix_text("Achieved low-Earth orbit");
|
p2.set_postfix_text("Achieved low-Earth orbit");
|
||||||
p2.set_foreground_color(indicators::Color::WHITE);
|
p2.set_foreground_color(indicators::Color::WHITE);
|
||||||
|
p2.hide_elapsed_time();
|
||||||
|
p2.hide_remaining_time();
|
||||||
std::vector<std::string> ship_trail{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"};
|
std::vector<std::string> ship_trail{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"};
|
||||||
std::atomic<int> ship_trail_index{0};
|
std::atomic<int> ship_trail_index{0};
|
||||||
auto job2 = [&p2, &ship_trail_index, &ship_trail]() {
|
auto job2 = [&p2, &ship_trail_index, &ship_trail]() {
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void _save_start_time() {
|
void _save_start_time() {
|
||||||
if (_show_elapsed_time && !_saved_start_time) {
|
if ((_show_elapsed_time || _show_remaining_time) && !_saved_start_time) {
|
||||||
_start_time_point = std::chrono::high_resolution_clock::now();
|
_start_time_point = std::chrono::high_resolution_clock::now();
|
||||||
_saved_start_time = true;
|
_saved_start_time = true;
|
||||||
}
|
}
|
||||||
@@ -223,6 +223,8 @@ private:
|
|||||||
if (_show_remaining_time) {
|
if (_show_remaining_time) {
|
||||||
if (_show_elapsed_time)
|
if (_show_elapsed_time)
|
||||||
std::cout << "<";
|
std::cout << "<";
|
||||||
|
else
|
||||||
|
std::cout << " [";
|
||||||
auto eta = std::chrono::nanoseconds(
|
auto eta = std::chrono::nanoseconds(
|
||||||
_progress > 0 ? static_cast<long long>(elapsed.count() * 100 / _progress) : 0);
|
_progress > 0 ? static_cast<long long>(elapsed.count() * 100 / _progress) : 0);
|
||||||
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
|
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void _save_start_time() {
|
void _save_start_time() {
|
||||||
if (_show_elapsed_time && !_saved_start_time) {
|
if ((_show_elapsed_time || _show_remaining_time) && !_saved_start_time) {
|
||||||
_start_time_point = std::chrono::high_resolution_clock::now();
|
_start_time_point = std::chrono::high_resolution_clock::now();
|
||||||
_saved_start_time = true;
|
_saved_start_time = true;
|
||||||
}
|
}
|
||||||
@@ -231,6 +231,8 @@ private:
|
|||||||
if (_show_remaining_time) {
|
if (_show_remaining_time) {
|
||||||
if (_show_elapsed_time)
|
if (_show_elapsed_time)
|
||||||
std::cout << "<";
|
std::cout << "<";
|
||||||
|
else
|
||||||
|
std::cout << " [";
|
||||||
auto eta = std::chrono::nanoseconds(
|
auto eta = std::chrono::nanoseconds(
|
||||||
_progress > 0 ? static_cast<long long>(elapsed.count() * 100 / _progress) : 0);
|
_progress > 0 ? static_cast<long long>(elapsed.count() * 100 / _progress) : 0);
|
||||||
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
|
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void _save_start_time() {
|
void _save_start_time() {
|
||||||
if (_show_elapsed_time && !_saved_start_time) {
|
if ((_show_elapsed_time || _show_remaining_time) && !_saved_start_time) {
|
||||||
_start_time_point = std::chrono::high_resolution_clock::now();
|
_start_time_point = std::chrono::high_resolution_clock::now();
|
||||||
_saved_start_time = true;
|
_saved_start_time = true;
|
||||||
}
|
}
|
||||||
@@ -199,6 +199,8 @@ private:
|
|||||||
if (_show_remaining_time) {
|
if (_show_remaining_time) {
|
||||||
if (_show_elapsed_time)
|
if (_show_elapsed_time)
|
||||||
std::cout << "<";
|
std::cout << "<";
|
||||||
|
else
|
||||||
|
std::cout << " [";
|
||||||
auto eta = std::chrono::nanoseconds(
|
auto eta = std::chrono::nanoseconds(
|
||||||
_progress > 0 ? static_cast<long long>(elapsed.count() * 100 / _progress) : 0);
|
_progress > 0 ? static_cast<long long>(elapsed.count() * 100 / _progress) : 0);
|
||||||
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
|
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
#include <chrono>
|
||||||
#include <indicators/block_progress_bar.hpp>
|
#include <indicators/block_progress_bar.hpp>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
@@ -14,6 +14,8 @@ int main() {
|
|||||||
bar.start_bar_with("[");
|
bar.start_bar_with("[");
|
||||||
bar.end_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
|
// Update bar state
|
||||||
auto progress = 0.0f;
|
auto progress = 0.0f;
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ int main() {
|
|||||||
bar.fill_bar_remainder_with("-");
|
bar.fill_bar_remainder_with("-");
|
||||||
bar.end_bar_with("]");
|
bar.end_bar_with("]");
|
||||||
bar.set_foreground_color(indicators::Color::YELLOW);
|
bar.set_foreground_color(indicators::Color::YELLOW);
|
||||||
|
bar.hide_elapsed_time();
|
||||||
|
bar.hide_remaining_time();
|
||||||
|
|
||||||
// As configured, the bar will look like this:
|
// As configured, the bar will look like this:
|
||||||
//
|
//
|
||||||
@@ -19,15 +21,12 @@ int main() {
|
|||||||
//
|
//
|
||||||
|
|
||||||
std::atomic<size_t> index{0};
|
std::atomic<size_t> index{0};
|
||||||
std::vector<std::string> status_text =
|
std::vector<std::string> status_text = {"Rocket.exe is not responding",
|
||||||
{
|
"Finding a replacement engineer",
|
||||||
"Rocket.exe is not responding",
|
"Buying more snacks",
|
||||||
"Finding a replacement engineer",
|
"Assimilating the modding community",
|
||||||
"Buying more snacks",
|
"Crossing fingers",
|
||||||
"Assimilating the modding community",
|
"Porting KSP to a Nokia 3310"};
|
||||||
"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
|
// 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
|
// You can use bar.set_postfix_text(...) to append text to the right
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
#include <chrono>
|
||||||
#include <indicators/progress_bar.hpp>
|
#include <indicators/progress_bar.hpp>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
indicators::ProgressBar bar;
|
indicators::ProgressBar bar;
|
||||||
@@ -14,6 +14,8 @@ int main() {
|
|||||||
bar.end_bar_with("]");
|
bar.end_bar_with("]");
|
||||||
bar.set_postfix_text("Getting started");
|
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
|
// Update bar state
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
#include <chrono>
|
||||||
#include <indicators/progress_bar.hpp>
|
#include <indicators/progress_bar.hpp>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
indicators::ProgressBar bar;
|
indicators::ProgressBar bar;
|
||||||
@@ -14,6 +14,8 @@ int main() {
|
|||||||
bar.end_bar_with("]");
|
bar.end_bar_with("]");
|
||||||
bar.set_postfix_text("Getting started");
|
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
|
// Update bar state
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ int main() {
|
|||||||
spinner.set_postfix_text("Checking credentials");
|
spinner.set_postfix_text("Checking credentials");
|
||||||
spinner.set_foreground_color(indicators::Color::YELLOW);
|
spinner.set_foreground_color(indicators::Color::YELLOW);
|
||||||
spinner.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"});
|
spinner.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"});
|
||||||
|
spinner.hide_elapsed_time();
|
||||||
|
spinner.hide_remaining_time();
|
||||||
|
|
||||||
// Update spinner state
|
// Update spinner state
|
||||||
auto job = [&spinner]() {
|
auto job = [&spinner]() {
|
||||||
|
|||||||
Reference in New Issue
Block a user