mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-12 01:18:52 +08:00
Added sample for smooth block progress bar
This commit is contained in:
32
samples/block_progress_bar.cpp
Normal file
32
samples/block_progress_bar.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#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);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user