-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.cpp
50 lines (46 loc) · 2.21 KB
/
demo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "pgbar/pgbar.hpp"
#include <chrono>
#include <random>
#include <thread>
#include <vector>
int main()
{
#if _WIN32
system( "chcp 65001" );
#endif
auto bar = pgbar::make_multi( pgbar::config::Line( pgbar::option::Description( "Eating something...." ),
pgbar::option::TrueMesg( "✔ Mission Accomplished" ),
pgbar::option::TrueColor( pgbar::color::Green ),
pgbar::option::FalseMesg( "❌ Mission failed" ),
pgbar::option::FalseColor( pgbar::color::Red ),
pgbar::option::InfoColor( "#7D7" ) ),
pgbar::config::Line( pgbar::option::Description( "Picking something..." ),
pgbar::option::TrueMesg( "✔ Mission Complete" ),
pgbar::option::TrueColor( pgbar::color::Green ),
pgbar::option::FalseMesg( "❌ Mission failed" ),
pgbar::option::FalseColor( pgbar::color::Red ),
pgbar::option::InfoColor( "#7BD" ) ) );
std::vector<std::thread> pool;
pool.emplace_back( std::thread( [&bar]() {
std::mt19937 rd { std::random_device {}() };
bar.iterate<0>( 50000, [&rd]( int ) {
std::this_thread::sleep_for(
std::chrono::microseconds( std::uniform_int_distribution<int>( 700, 1100 )( rd ) ) );
} );
} ) );
pool.emplace_back( std::thread( [&bar]() {
std::mt19937 rd { std::random_device {}() };
bar.config<1>().tasks( 10000 );
const std::size_t terminate_val = 5000 + std::uniform_int_distribution<int>( 10, 1000 )( rd );
for ( std::size_t i = 0; i < terminate_val; ++i ) {
bar.tick<1>();
std::this_thread::sleep_for(
std::chrono::microseconds( std::uniform_int_distribution<int>( 1100, 3000 )( rd ) ) );
}
bar.reset<1>( false );
} ) );
for ( auto& td : pool )
if ( td.joinable() )
td.join();
bar.wait();
}