cpptqdm icon indicating copy to clipboard operation
cpptqdm copied to clipboard

select adaptive width for process bar

Open Unsigned-Long opened this issue 8 months ago • 0 comments

  • Add .gitignore and CMakeLists.txt files.
  • Select adaptive width for the process bar. when the width of the output message is larger than the width of the terminal, the message line can not be flushed. This can be solved by selecting a suitable width of the the process bar at the beginning (the origin width is 40).
  • The adaptive width module works well on both ubuntu and windows.
        int width = []() {
#ifdef __linux__
          struct winsize win {};
          ioctl(0, TIOCGWINSZ, &win);
          unsigned short width = win.ws_col;
#else
          CONSOLE_SCREEN_BUFFER_INFO csbi;
          GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
          unsigned short width = csbi.srWindow.Right - csbi.srWindow.Left;
#endif
          // return the space left for process bar 
          // '60' is an experience value to exclude other output info, such as percent, time elapsed, etc.
          return std::max((int)width - 60, 1);
        }();

fig1

Unsigned-Long avatar Jun 04 '24 09:06 Unsigned-Long