mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Implemented indeterminate progress bar w/ sample
This commit is contained in:
@@ -29,3 +29,6 @@ target_link_libraries(dynamic_progress PRIVATE indicators::indicators)
|
||||
add_executable(max_progress max_progress.cpp)
|
||||
target_link_libraries(max_progress PRIVATE indicators::indicators)
|
||||
|
||||
add_executable(indeterminate_progress_bar indeterminate_progress_bar.cpp)
|
||||
target_link_libraries(indeterminate_progress_bar PRIVATE indicators::indicators)
|
||||
|
||||
|
||||
38
samples/indeterminate_progress_bar.cpp
Normal file
38
samples/indeterminate_progress_bar.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <chrono>
|
||||
#include <indicators/indeterminate_progress_bar.hpp>
|
||||
#include <indicators/cursor_control.hpp>
|
||||
#include <indicators/termcolor.hpp>
|
||||
#include <thread>
|
||||
|
||||
int main() {
|
||||
indicators::IndeterminateProgressBar bar{
|
||||
indicators::option::BarWidth{40},
|
||||
indicators::option::Start{"["},
|
||||
indicators::option::Fill{"·"},
|
||||
indicators::option::Lead{"<==>"},
|
||||
indicators::option::End{"]"},
|
||||
indicators::option::PostfixText{"Checking for Updates"},
|
||||
indicators::option::ForegroundColor{indicators::Color::yellow},
|
||||
indicators::option::FontStyles{
|
||||
std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}
|
||||
};
|
||||
|
||||
indicators::show_console_cursor(false);
|
||||
|
||||
auto job = [&bar]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||
bar.mark_as_completed();
|
||||
std::cout << termcolor::bold << termcolor::green
|
||||
<< "System is up to date!\n" << termcolor::reset;
|
||||
};
|
||||
std::thread job_completion_thread(job);
|
||||
|
||||
// Update bar state
|
||||
while (!bar.is_completed()) {
|
||||
bar.tick();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
}
|
||||
|
||||
job_completion_thread.join();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user