17 m_bar_width(0), m_max_message_size(max_message_size),
18 m_last_percentage(0), m_terminal_width(get_terminal_width())
20 if (m_terminal_width <= 8)
25 m_bar_width = m_terminal_width - 7;
26 if (max_message_size != 0)
28 m_bar_width -= max_message_size + 1;
42 if (percent < 0) percent = m_last_percentage;
43 if (percent > 99) percent = 99;
49 progress = std::clamp(progress, 0.f, 1.f);
50 m_last_percentage = (
u32)(progress * 100.0f);
52 if (m_terminal_width <= 8)
57 u32 pos = (
u32)(m_bar_width * progress);
59 if (pos <= m_printed_progress && m_last_message ==
message)
65 m_printed_progress = pos;
70 bar += std::string(pos,
'=');
72 if (pos < m_bar_width)
76 if (pos + 1 < m_bar_width)
78 bar += std::string(m_bar_width - pos - 1,
' ');
82 if (print_message.size() > m_max_message_size)
84 if (m_max_message_size <= 3)
86 print_message = std::string(m_max_message_size,
'.');
90 print_message = print_message.substr(0, m_max_message_size - 3) +
"...";
94 std::stringstream
str;
95 str <<
"[" << bar <<
"] ";
97 str << std::right << std::setw(3) << m_last_percentage <<
'%';
99 if (!print_message.empty())
101 str <<
" " << print_message;
107 if (
output.size() < (
u32)m_terminal_width)
109 std::cerr << std::string(m_terminal_width -
output.size(),
' ');
112 std::cerr <<
"\r" << std::flush;
117 if (m_terminal_width <= 8)
121 std::cerr << std::string(m_terminal_width,
' ') <<
"\r" << std::flush;
126 m_printed_progress = 0;
127 m_last_message =
"$^äü+";
130 int ProgressPrinter::get_terminal_width()
133 int retval = ioctl(STDERR_FILENO, TIOCGWINSZ, &size);
static std::function< void(int, const std::string &)> s_progress_indicator_function
ProgressPrinter(u32 max_message_size=0)
void print_message_to_gui(const std::string &message)
void print_progress_to_gui(int percent=-1)
void print_progress_to_stderr(float progress, const std::string &message="")
message(VERBOSE "Qt5Widgets_LIBRARIES: ${Qt5Widgets_LIBRARIES}") elseif(NOT Qt5Widgets_FOUND) set(Missing_package "TRUE") if(APPLE AND CMAKE_HOST_APPLE) message(STATUS "To install qt5 on MacOS using homebrew run following command
const int dont_believe_in_terminal_width_bigger_than_this_value