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

Method print_progress

src/indicators.hpp:2202–2276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2200
2201public:
2202 void print_progress(bool from_multi_progress = false) {
2203 std::lock_guard<std::mutex> lock{mutex_};
2204
2205 auto &os = get_value<details::ProgressBarOption::stream>();
2206
2207 const auto type = get_value<details::ProgressBarOption::progress_type>();
2208 const auto min_progress =
2209 get_value<details::ProgressBarOption::min_progress>();
2210 const auto max_progress =
2211 get_value<details::ProgressBarOption::max_progress>();
2212 if (multi_progress_mode_ && !from_multi_progress) {
2213 if ((type == ProgressType::incremental && progress_ >= max_progress) ||
2214 (type == ProgressType::decremental && progress_ <= min_progress)) {
2215 get_value<details::ProgressBarOption::completed>() = true;
2216 }
2217 return;
2218 }
2219 auto now = std::chrono::high_resolution_clock::now();
2220 if (!get_value<details::ProgressBarOption::completed>())
2221 elapsed_ = std::chrono::duration_cast<std::chrono::nanoseconds>(
2222 now - start_time_point_);
2223
2224 if (get_value<details::ProgressBarOption::foreground_color>() !=
2225 Color::unspecified)
2226 details::set_stream_color(
2227 os, get_value<details::ProgressBarOption::foreground_color>());
2228
2229 for (auto &style : get_value<details::ProgressBarOption::font_styles>())
2230 details::set_font_style(os, style);
2231
2232 const auto prefix_pair = get_prefix_text();
2233 const auto prefix_text = prefix_pair.first;
2234 const auto prefix_length = prefix_pair.second;
2235 os << "\r" << prefix_text;
2236
2237 os << get_value<details::ProgressBarOption::start>();
2238
2239 details::ProgressScaleWriter writer{
2240 os, get_value<details::ProgressBarOption::bar_width>(),
2241 get_value<details::ProgressBarOption::fill>(),
2242 get_value<details::ProgressBarOption::lead>(),
2243 get_value<details::ProgressBarOption::remainder>()};
2244 writer.write(double(progress_) / double(max_progress) * 100.0f);
2245
2246 os << get_value<details::ProgressBarOption::end>();
2247
2248 const auto postfix_pair = get_postfix_text();
2249 const auto postfix_text = postfix_pair.first;
2250 const auto postfix_length = postfix_pair.second;
2251 os << postfix_text;
2252
2253 // Get length of prefix text and postfix text
2254 const auto start_length = get_value<details::ProgressBarOption::start>().size();
2255 const auto bar_width = get_value<details::ProgressBarOption::bar_width>();
2256 const auto end_length = get_value<details::ProgressBarOption::end>().size();
2257 const auto terminal_width = terminal_size().second;
2258 // prefix + bar_width + postfix should be <= terminal_width
2259 const int remaining = terminal_width - (prefix_length + start_length + bar_width + end_length + postfix_length);

Callers 2

print_progressMethod · 0.45
print_progressMethod · 0.45

Calls 4

set_stream_colorFunction · 0.85
set_font_styleFunction · 0.85
terminal_sizeFunction · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected