mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-15 11:58:52 +08:00
Added sample to show max_progress working with iterables. Updated README
This commit is contained in:
50
samples/block_progress_bar_iterable.cpp
Normal file
50
samples/block_progress_bar_iterable.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <chrono>
|
||||
#include <indicators/block_progress_bar.hpp>
|
||||
#include <indicators/cursor_control.hpp>
|
||||
#include <thread>
|
||||
|
||||
int main() {
|
||||
|
||||
// Hide cursor
|
||||
indicators::show_console_cursor(false);
|
||||
|
||||
// Random list of numbers
|
||||
std::vector<size_t> numbers;
|
||||
for (size_t i = 0; i < 1259438; ++i) {
|
||||
numbers.push_back(i);
|
||||
}
|
||||
|
||||
using namespace indicators;
|
||||
BlockProgressBar bar{
|
||||
option::BarWidth{80},
|
||||
option::ForegroundColor{Color::white},
|
||||
option::FontStyles{
|
||||
std::vector<FontStyle>{FontStyle::bold}},
|
||||
option::MaxProgress{numbers.size()}
|
||||
};
|
||||
|
||||
std::cout << "Iterating over a list of numbers (size = "
|
||||
<< numbers.size() << ")\n";
|
||||
|
||||
std::vector<size_t> result;
|
||||
for (size_t i = 0; i < numbers.size(); ++i) {
|
||||
|
||||
// Perform some computation
|
||||
result.push_back(numbers[i] * numbers[i]);
|
||||
|
||||
// Show iteration as postfix text
|
||||
bar.set_option(option::PostfixText{
|
||||
std::to_string(i) + "/" + std::to_string(numbers.size())
|
||||
});
|
||||
|
||||
// update progress bar
|
||||
bar.tick();
|
||||
}
|
||||
|
||||
bar.mark_as_completed();
|
||||
|
||||
// Show cursor
|
||||
indicators::show_console_cursor(true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user