Fix progress bar

This commit is contained in:
Alexey Milovidov 2022-02-21 00:25:07 +01:00
parent 1d5e99362f
commit 829bd066c4

View File

@ -244,9 +244,14 @@ void ProgressIndication::writeProgress()
double bar_width = UnicodeBar::getWidth(current_count, 0, max_count, width_of_progress_bar);
std::string bar = UnicodeBar::render(bar_width);
/// Whitespaces after the progress bar.
std::string whitespaces;
if (width_of_progress_bar > static_cast<int64_t>(bar.size() / UNICODE_BAR_CHAR_SIZE))
whitespaces.assign(width_of_progress_bar - bar.size() - profiling_msg.size() / UNICODE_BAR_CHAR_SIZE, ' ');
if (profiling_msg.empty())
{
message << "\033[0;32m" << bar << "\033[0m";
message << "\033[0;32m" << bar << "\033[0m" << whitespaces;
}
else
{
@ -257,23 +262,15 @@ void ProgressIndication::writeProgress()
/// Render profiling_msg at left on top of the progress bar.
message << "\033[30;42m" << profiling_msg << "\033[0m"
<< "\033[0;32m" << bar.substr(profiling_msg.size()) << "\033[0m";
/// Whitespaces after the progress bar.
if (width_of_progress_bar > static_cast<int64_t>(bar.size() / UNICODE_BAR_CHAR_SIZE))
message << std::string(width_of_progress_bar - bar.size() / UNICODE_BAR_CHAR_SIZE, ' ');
<< "\033[0;32m" << bar.substr(profiling_msg.size()) << "\033[0m"
<< whitespaces;
}
else
{
/// Render profiling_msg at right after the progress bar.
message << "\033[0;32m" << bar << "\033[0m";
/// Whitespaces after the progress bar.
if (width_of_progress_bar > static_cast<int64_t>(profiling_msg.size()) + static_cast<int64_t>(bar.size() / UNICODE_BAR_CHAR_SIZE))
message << std::string(width_of_progress_bar - profiling_msg.size() - bar.size() / UNICODE_BAR_CHAR_SIZE, ' ');
message << "\033[2m" << profiling_msg << "\033[0m";
message << "\033[0;32m" << bar << "\033[0m"
<< whitespaces << "\033[2m" << profiling_msg << "\033[0m";
}
}
}