3636#include < cerrno>
3737#include < cstddef>
3838
39+ #ifndef _WIN32
40+ #include < sys/ioctl.h>
41+ #endif
42+
3943namespace
4044{
4145 inline void write_all_fd (int fd, const char *data, std::size_t len) noexcept
@@ -59,6 +63,36 @@ namespace
5963} // namespace
6064#endif
6165
66+ #ifndef _WIN32
67+ namespace
68+ {
69+ std::size_t terminal_width () noexcept
70+ {
71+ struct winsize ws{};
72+
73+ if (::ioctl (STDOUT_FILENO , TIOCGWINSZ , &ws) == 0 && ws.ws_col > 0 )
74+ return static_cast <std::size_t >(ws.ws_col );
75+
76+ return 120 ;
77+ }
78+
79+ std::string truncate_progress_text (const std::string &line, std::size_t maxWidth)
80+ {
81+ if (maxWidth == 0 )
82+ return " " ;
83+
84+ if (line.size () <= maxWidth)
85+ return line;
86+
87+ if (maxWidth <= 3 )
88+ return std::string (maxWidth, ' .' );
89+
90+ const std::size_t keep = maxWidth - 3 ;
91+ return line.substr (0 , keep) + " ..." ;
92+ }
93+ }
94+ #endif
95+
6296namespace vix ::cli::build
6397{
6498 namespace util = vix::cli::util;
@@ -355,15 +389,21 @@ namespace vix::cli::build
355389 if (quiet)
356390 return ;
357391
358- std::string out = " \r " + line;
392+ const std::size_t width = terminal_width ();
393+
394+ std::string visibleLine = line;
395+ if (width > 1 )
396+ visibleLine = truncate_progress_text (line, width - 1 );
397+
398+ std::string out = " \r " + visibleLine;
359399
360- if (lastRenderedWidth > line .size ())
361- out.append (lastRenderedWidth - line .size (), ' ' );
400+ if (lastRenderedWidth > visibleLine .size ())
401+ out.append (lastRenderedWidth - visibleLine .size (), ' ' );
362402
363403 write_all_fd (STDOUT_FILENO , out.data (), out.size ());
364404
365405 progressVisible = true ;
366- lastRenderedWidth = std::max (lastRenderedWidth, line .size ());
406+ lastRenderedWidth = std::max (lastRenderedWidth, visibleLine .size ());
367407 };
368408
369409 auto flush_progress_line = [&]() -> void
@@ -398,6 +438,9 @@ namespace vix::cli::build
398438 if (line.find (" Re-running CMake..." ) != std::string::npos)
399439 return false ;
400440
441+ if (line.find (" Copy compile_commands.json to project root" ) != std::string::npos)
442+ return false ;
443+
401444 if (line.rfind (" FAILED:" , 0 ) == 0 )
402445 return true ;
403446
0 commit comments