Process has done i out of n rounds, and we want a bar of width w and resolution r. TODO put this i an library
| 112 | // and we want a bar of width w and resolution r. |
| 113 | // TODO put this i an library |
| 114 | static inline void loadBar(int x, int n, int r = 100, int w = 50) |
| 115 | { |
| 116 | r = std::min(r, n); |
| 117 | |
| 118 | // Only update r times. |
| 119 | if ( x % (n/r) != 0 ) return; |
| 120 | |
| 121 | // Calculuate the ratio of complete-to-incomplete. |
| 122 | float ratio = x/(float)n; |
| 123 | int c = ratio * w; |
| 124 | |
| 125 | // Show the percentage complete. |
| 126 | std::cout << std::setw(3) << (int)(ratio*100) << "% ["; |
| 127 | |
| 128 | // Show the load bar. |
| 129 | for (int x=0; x<c; x++) |
| 130 | std::cout << '='; |
| 131 | |
| 132 | for (int x=c; x<w; x++) |
| 133 | std::cout << ' '; |
| 134 | |
| 135 | std::cout << ']'; |
| 136 | |
| 137 | if (x != n) |
| 138 | // go to the beginning of the line |
| 139 | std::cout << '\r'; |
| 140 | else |
| 141 | std::cout << '\n'; |
| 142 | |
| 143 | std::cout << std::flush; |
| 144 | } |
| 145 | |
| 146 | static const char* dim2str(unsigned int dim) |
| 147 | { |