Readme updated

This commit is contained in:
Dawid Pilarski
2020-02-10 21:25:54 +01:00
committed by pilarski
parent d543453c0c
commit 07734c412b

187
README.md
View File

@@ -62,17 +62,17 @@ You can update the progress bar using `bar.tick()` which increments progress by
#include <chrono> #include <chrono>
int main() { int main() {
indicators::ProgressBar bar; using namespace indicators;
ProgressBar bar{
// Configure the bar option::BarWidth{50},
bar.set_bar_width(50); option::Start{"["},
bar.start_bar_with("["); option::Fill{"="},
bar.fill_bar_progress_with("="); option::Lead{">"},
bar.lead_bar_progress_with(">"); option::Remainder{" "},
bar.fill_bar_remainder_with(" "); option::End{"]"},
bar.end_bar_with("]"); option::PostfixText{"Extracting Archive"};
bar.set_postfix_text("Extracting Archive"); option::ForegroundColor{Color::GREEN};
bar.set_foreground_color(indicators::Color::GREEN); };
// Update bar state // Update bar state
while (true) { while (true) {
@@ -106,18 +106,17 @@ int main() {
// Hide cursor // Hide cursor
std::cout << "\e[?25l"; std::cout << "\e[?25l";
using namespace indicators;
indicators::ProgressBar bar; ProgressBar bar{
option::BarWidth{50},
// Configure the bar option::Start{"["},
bar.set_bar_width(50); option::Fill{"■"},
bar.start_bar_with("["); option::Lead{""},
bar.fill_bar_progress_with(""); option::Remainder{"-"},
bar.lead_bar_progress_with(""); option::End{" ]"},
bar.fill_bar_remainder_with("-"); option::PostfixText{"Loading dependency 1/4"},
bar.end_bar_with(" ]"); option::ForegroundColor{Color::CYAN}
bar.set_postfix_text("Loading dependency 1/4"); };
bar.set_foreground_color(indicators::Color::CYAN);
// Update bar state // Update bar state
bar.set_progress(10); // 10% done bar.set_progress(10); // 10% done
@@ -125,21 +124,21 @@ int main() {
// do some work // do some work
std::this_thread::sleep_for(std::chrono::milliseconds(800)); std::this_thread::sleep_for(std::chrono::milliseconds(800));
bar.set_postfix_text("Loading dependency 2/4"); bar.set_option(option::PostfixText{"Loading dependency 2/4"});
bar.set_progress(30); // 30% done bar.set_progress(30); // 30% done
// do some more work // do some more work
std::this_thread::sleep_for(std::chrono::milliseconds(700)); std::this_thread::sleep_for(std::chrono::milliseconds(700));
bar.set_postfix_text("Loading dependency 3/4"); bar.set_option(option::PostfixText{"Loading dependency 3/4"});
bar.set_progress(65); // 65% done bar.set_progress(65); // 65% done
// do final bit of work // do final bit of work
std::this_thread::sleep_for(std::chrono::milliseconds(900)); std::this_thread::sleep_for(std::chrono::milliseconds(900));
bar.set_postfix_text("Loaded dependencies!"); bar.set_option(option::PostfixText{"Loaded dependencies!"});
bar.set_progress(100); // all done bar.set_progress(100); // all done
@@ -166,21 +165,19 @@ All progress bars and spinners in `indicators` support showing time elapsed and
#include <thread> #include <thread>
int main() { int main() {
indicators::ProgressBar bar; using namespace indicators;
indicators::ProgressBar bar{
// Configure the bar option::BarWidth{50},
bar.set_bar_width(50); option::Start{" ["},
bar.start_bar_with(" ["); option::Fill{""},
bar.fill_bar_progress_with("█"); option::Lead{"█"},
bar.lead_bar_progress_with(""); option::Remainder{"-"},
bar.fill_bar_remainder_with("-"); option::End{"]"},
bar.end_bar_with("]"); option::PrefixText{"Training Gaze Network "👀},
bar.set_prefix_text("Training Gaze Network 👀"); option::ForegroundColor{Color::YELLOW}
bar.set_foreground_color(indicators::Color::YELLOW); option::ShowElapsedTime{true};
option::ShowRemainingTime{true};
// Show time elapsed and remaining };
bar.show_elapsed_time();
bar.show_remaining_time();
// Update bar state // Update bar state
while (true) { while (true) {
@@ -214,14 +211,14 @@ int main() {
// Hide cursor // Hide cursor
std::cout << "\e[?25l"; std::cout << "\e[?25l";
using namespace indicators;
indicators::BlockProgressBar bar; BlockProgressBar bar{
option::BarWidth{80},
// Configure the bar option::Start{"["},
bar.set_bar_width(80); option::End{"]"},
bar.start_bar_with("["); option::ForegroundColor{Color::WHITE}
bar.end_bar_with("]"); };
bar.set_foreground_color(indicators::Color::WHITE);
// Update bar state // Update bar state
auto progress = 0.0f; auto progress = 0.0f;
@@ -257,45 +254,49 @@ Below is an example `MultiProgress` object that manages three `ProgressBar` obje
#include <indicators/progress_bar.hpp> #include <indicators/progress_bar.hpp>
int main() { int main() {
using namespace indicators;
// Configure first progress bar // Configure first progress bar
indicators::ProgressBar bar1; ProgressBar bar1{
bar1.set_bar_width(50); option::BarWidth{50},
bar1.start_bar_with("["); option::Start{"["},
bar1.fill_bar_progress_with("■"); option::Fill{"■"},
bar1.lead_bar_progress_with("■"); option::Lead{"■"},
bar1.fill_bar_remainder_with(" "); option::Remainder{" "},
bar1.end_bar_with(" ]"); option::End{" ]"},
bar1.set_foreground_color(indicators::Color::YELLOW); option::ForegroundColor{Color::YELLOW},
bar1.show_elapsed_time(); option::ShowElapsedTime{true},
bar1.show_remaining_time(); option::ShowRemainingTime{true},
bar1.set_prefix_text("Progress Bar #1 "); option::PrefixText{"Progress Bar #1 "}
};
// Configure second progress bar // Configure second progress bar
indicators::ProgressBar bar2;
bar2.set_bar_width(50); ProgressBar bar1{
bar2.start_bar_with("["); option::BarWidth{50},
bar2.fill_bar_progress_with("="); option::Start{"["},
bar2.lead_bar_progress_with(">"); option::Fill{"="},
bar2.fill_bar_remainder_with(" "); option::Lead{">"},
bar2.end_bar_with(" ]"); option::Remainder{" "},
bar2.set_foreground_color(indicators::Color::CYAN); option::End{" ]"},
bar2.show_elapsed_time(); option::ForegroundColor{Color::CYAN},
bar2.show_remaining_time(); option::ShowElapsedTime{true},
bar2.set_prefix_text("Progress Bar #2 "); option::ShowRemainingTime{true},
option::PrefixText{"Progress Bar #2 "}
};
// Configure third progress bar // Configure third progress bar
indicators::ProgressBar bar3; indicators::ProgressBar bar3{
bar3.set_bar_width(50); option::BarWidth{50},
bar3.start_bar_with("["); option::Start{"["},
bar3.fill_bar_progress_with("#"); option::Fill{"#"},
bar3.lead_bar_progress_with("#"); option::Lead{"#"},
bar3.fill_bar_remainder_with(" "); option::Remainder{" "},
bar3.end_bar_with(" ]"); option::End{" ]"},
bar3.set_foreground_color(indicators::Color::RED); option::ForegroundColor{Color::RED},
bar3.show_elapsed_time(); option::ShowElapsedTime{true},
bar3.show_remaining_time(); option::ShowRemainingTime{true},
bar3.set_prefix_text("Progress Bar #3 "); option::PrefixText{"Progress Bar #3 "}
};
// Construct MultiProgress object // Construct MultiProgress object
indicators::MultiProgress<indicators::ProgressBar, 3> bars(bar1, bar2, bar3); indicators::MultiProgress<indicators::ProgressBar, 3> bars(bar1, bar2, bar3);
@@ -359,22 +360,22 @@ ProgressSpinner has a vector of strings: `spinner_states`. At each update, the s
#include <indicators/progress_spinner.hpp> #include <indicators/progress_spinner.hpp>
int main() { int main() {
indicators::ProgressSpinner spinner; using namespace indicators;
indicators::ProgressSpinner spinner{
// Configure the spinner option::PostfixText{"Checking credentials"},
spinner.set_postfix_text("Checking credentials"); option::ForegroundColor{Color::YELLOW},
spinner.set_foreground_color(indicators::Color::YELLOW); option::SpinnerStates{std::vector<std::string>{"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"};}
spinner.set_spinner_states({"⠈", "⠐", "⠠", "⢀", "⡀", "⠄", "⠂", "⠁"}); };
// Update spinner state // Update spinner state
auto job = [&spinner]() { auto job = [&spinner]() {
while (true) { while (true) {
if (spinner.is_completed()) { if (spinner.is_completed()) {
spinner.set_foreground_color(indicators::Color::GREEN); spinner.set_option(option::ForegroundColor{Color::GREEN});
spinner.set_prefix_text("✔"); spinner.set_option(option::PrefixText{"✔"});
spinner.hide_spinner(); spinner.set_option(option::SpinnerShow{false});
spinner.hide_percentage(); spinner.set_option(option::ShowPercentage{false});
spinner.set_postfix_text("Authenticated!"); spinner.set_option(option::PostfixText{"Authenticated!"});
spinner.mark_as_completed(); spinner.mark_as_completed();
break; break;
} else } else