1 #include "ProgressBar.h" 3 #define ANSI_COLOR_RED "\x1b[31m" 4 #define ANSI_COLOR_GREEN "\x1b[32m" 5 #define ANSI_COLOR_YELLOW "\x1b[33m" 6 #define ANSI_COLOR_BLUE "\x1b[34m" 7 #define ANSI_COLOR_MAGENTA "\x1b[35m" 8 #define ANSI_COLOR_CYAN "\x1b[36m" 9 #define ANSI_COLOR_RESET "\x1b[0m" 20 std::cerr <<
"Assuming 100 events in ProgressBar" << std::endl;
38 maxEntry = maxEntryInit;
55 if(percentage>=100)
return;
58 Int_t seconds = Int_t(watch.RealTime());
59 Int_t hours = seconds / 3600;
60 hours = hours < 0 ? 0 : hours;
61 seconds = seconds - hours * 3600;
62 Int_t mins = seconds / 60;
63 mins = mins < 0 ? 0 : mins;
65 seconds = seconds - mins * 60;
68 double ratio = double(counter)/maxEntry;
71 if(ratio*100 > percentage){
73 while(ratio*100 > percentage){
80 fprintf(stderr,
"\r");
83 fprintf(stderr, ANSI_COLOR_RED);
84 fprintf(stderr,
"%3u%%", (UInt_t)(percentage) );
85 fprintf(stderr, ANSI_COLOR_RESET);
86 fprintf(stderr,
" [");
89 fprintf(stderr, ANSI_COLOR_BLUE);
90 fprintf(stderr,
"%02d:%02d:%02d", hours, mins, seconds);
91 for (UInt_t i=8; i<percentage; i++){
94 fprintf(stderr, ANSI_COLOR_RESET);
96 Int_t startSpace = percentage > 8 ? percentage : 8;
97 for (Int_t i=startSpace; i<100; i++){
101 fprintf(stderr,
"]");
104 if(percentage>=100) fprintf(stderr,
"\n");
119 std::cout << percentage <<
"\t" << counter <<
"\t" << maxEntry << std::endl;
ProgressBar()
Default constructor - don't use this.
void operator++(int)
Increment operator, use when you have completed one iteration of the main loop.
void status()
For debugging, prints state of internal variables.