From 21391f3ca01ca6a94f2cd44b4269fafddddd8463 Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Mon, 16 Dec 2019 09:11:25 -0600 Subject: [PATCH] Added sample for smooth block progress bar --- samples/block_progress_bar.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 samples/block_progress_bar.cpp diff --git a/samples/block_progress_bar.cpp b/samples/block_progress_bar.cpp new file mode 100644 index 0000000..e1ce407 --- /dev/null +++ b/samples/block_progress_bar.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +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); + + // Update bar state + auto progress = 0.0f; + while (true) { + bar.set_progress(progress); + progress += 0.25f; + if (bar.is_completed()) + break; + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } + + // Show cursor + std::cout << "\e[?25h"; + + return 0; +}