MCPcopy Create free account
hub / github.com/KTH-RPL/dufomap / print_progress

Method print_progress

src/indicators.hpp:3186–3243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3184
3185public:
3186 void print_progress() {
3187 std::lock_guard<std::mutex> lock{mutex_};
3188
3189 auto &os = get_value<details::ProgressBarOption::stream>();
3190
3191 const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
3192 auto now = std::chrono::high_resolution_clock::now();
3193 auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(now - start_time_point_);
3194
3195 if (get_value<details::ProgressBarOption::foreground_color>() != Color::unspecified)
3196 details::set_stream_color(os, get_value<details::ProgressBarOption::foreground_color>());
3197
3198 for (auto &style : get_value<details::ProgressBarOption::font_styles>())
3199 details::set_font_style(os, style);
3200
3201 os << get_value<details::ProgressBarOption::prefix_text>();
3202 if (get_value<details::ProgressBarOption::spinner_show>())
3203 os << get_value<details::ProgressBarOption::spinner_states>()
3204 [index_ % get_value<details::ProgressBarOption::spinner_states>().size()];
3205 if (get_value<details::ProgressBarOption::show_percentage>()) {
3206 os << " " << std::size_t(progress_ / double(max_progress) * 100) << "%";
3207 }
3208
3209 if (get_value<details::ProgressBarOption::show_elapsed_time>()) {
3210 os << " [";
3211 details::write_duration(os, elapsed);
3212 }
3213
3214 if (get_value<details::ProgressBarOption::show_remaining_time>()) {
3215 if (get_value<details::ProgressBarOption::show_elapsed_time>())
3216 os << "<";
3217 else
3218 os << " [";
3219 auto eta = std::chrono::nanoseconds(
3220 progress_ > 0
3221 ? static_cast<long long>(std::ceil(float(elapsed.count()) *
3222 max_progress / progress_))
3223 : 0);
3224 auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
3225 details::write_duration(os, remaining);
3226 os << "]";
3227 } else {
3228 if (get_value<details::ProgressBarOption::show_elapsed_time>())
3229 os << "]";
3230 }
3231
3232 if (get_value<details::ProgressBarOption::max_postfix_text_len>() == 0)
3233 get_value<details::ProgressBarOption::max_postfix_text_len>() = 10;
3234 os << " " << get_value<details::ProgressBarOption::postfix_text>()
3235 << std::string(get_value<details::ProgressBarOption::max_postfix_text_len>(), ' ') << "\r";
3236 os.flush();
3237 index_ += 1;
3238 if (progress_ > max_progress) {
3239 get_value<details::ProgressBarOption::completed>() = true;
3240 }
3241 if (get_value<details::ProgressBarOption::completed>())
3242 os << termcolor::reset << std::endl;
3243 }

Callers

nothing calls this directly

Calls 3

set_stream_colorFunction · 0.85
set_font_styleFunction · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected