| 233 | |
| 234 | private: |
| 235 | void draw(int current, bool force) |
| 236 | { |
| 237 | if(total_ <= 0 and not force) |
| 238 | { |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | const double fraction = total_ > 0 |
| 243 | ? static_cast<double>(current) / static_cast<double>(total_) : 1.0; |
| 244 | const double elapsed = |
| 245 | std::chrono::duration<double>(clock_type::now() - start_).count(); |
| 246 | const double rate = elapsed > 0.0 |
| 247 | ? static_cast<double>(current) / elapsed : 0.0; |
| 248 | const double total = (current > 0 and total_ > current) |
| 249 | ? elapsed * (static_cast<double>(total_) / static_cast<double>(current)) |
| 250 | : 0.0; |
| 251 | |
| 252 | std::ostringstream suffix; |
| 253 | suffix << "] " |
| 254 | << current << "/" << total_ << " " |
| 255 | << std::fixed << std::setprecision(1) << (fraction * 100.0) |
| 256 | << "% " |
| 257 | << std::fixed << std::setprecision(1) << rate << "/s " |
| 258 | << "elapsed: " << format_duration(elapsed) << " [sec]" |
| 259 | << " total: " << format_duration(total) << " [sec]"; |
| 260 | const std::string suffix_text = suffix.str(); |
| 261 | |
| 262 | const std::string prefix = label_ + ": ["; |
| 263 | const int available = 100 |
| 264 | - static_cast<int>(prefix.size()) |
| 265 | - static_cast<int>(suffix_text.size()); |
| 266 | const int width = std::max(0, std::min(40, available)); |
| 267 | const int filled = std::min(width, static_cast<int>(fraction * width)); |
| 268 | |
| 269 | std::ostringstream line; |
| 270 | line << prefix; |
| 271 | for(int i = 0; i < width; ++i) |
| 272 | { |
| 273 | line << (i < filled ? '#' : '-'); |
| 274 | } |
| 275 | line << suffix_text; |
| 276 | |
| 277 | std::cerr << "\r\033[K" << line.str() << std::flush; |
| 278 | } |
| 279 | |
| 280 | private: |
| 281 | std::string label_; |
nothing calls this directly
no test coverage detected