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

Method print_progress

src/indicators.hpp:2510–2569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2508
2509public:
2510 void print_progress(bool from_multi_progress = false) {
2511 std::lock_guard<std::mutex> lock{mutex_};
2512
2513 auto &os = get_value<details::ProgressBarOption::stream>();
2514
2515 const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
2516 if (multi_progress_mode_ && !from_multi_progress) {
2517 if (progress_ > max_progress) {
2518 get_value<details::ProgressBarOption::completed>() = true;
2519 }
2520 return;
2521 }
2522
2523 if (get_value<details::ProgressBarOption::foreground_color>() != Color::unspecified)
2524 details::set_stream_color(os, get_value<details::ProgressBarOption::foreground_color>());
2525
2526 for (auto &style : get_value<details::ProgressBarOption::font_styles>())
2527 details::set_font_style(os, style);
2528
2529 const auto prefix_pair = get_prefix_text();
2530 const auto prefix_text = prefix_pair.first;
2531 const auto prefix_length = prefix_pair.second;
2532 os << "\r" << prefix_text;
2533
2534 os << get_value<details::ProgressBarOption::start>();
2535
2536 details::BlockProgressScaleWriter writer{os,
2537 get_value<details::ProgressBarOption::bar_width>()};
2538 writer.write(progress_ / max_progress * 100);
2539
2540 os << get_value<details::ProgressBarOption::end>();
2541
2542 const auto postfix_pair = get_postfix_text();
2543 const auto postfix_text = postfix_pair.first;
2544 const auto postfix_length = postfix_pair.second;
2545 os << postfix_text;
2546
2547 // Get length of prefix text and postfix text
2548 const auto start_length = get_value<details::ProgressBarOption::start>().size();
2549 const auto bar_width = get_value<details::ProgressBarOption::bar_width>();
2550 const auto end_length = get_value<details::ProgressBarOption::end>().size();
2551 const auto terminal_width = terminal_size().second;
2552 // prefix + bar_width + postfix should be <= terminal_width
2553 const int remaining = terminal_width - (prefix_length + start_length + bar_width + end_length + postfix_length);
2554 if (prefix_length == -1 || postfix_length == -1) {
2555 os << "\r";
2556 } else if (remaining > 0) {
2557 os << std::string(remaining, ' ') << "\r";
2558 } else if (remaining < 0) {
2559 // Do nothing. Maybe in the future truncate postfix with ...
2560 }
2561 os.flush();
2562
2563 if (progress_ > max_progress) {
2564 get_value<details::ProgressBarOption::completed>() = true;
2565 }
2566 if (get_value<details::ProgressBarOption::completed>() &&
2567 !from_multi_progress) // Don't std::endl if calling from MultiProgress

Callers

nothing calls this directly

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