aminnj / cpptqdm

(unofficial) tqdm-like single header c++ pretty progress bar
MIT License
203 stars 33 forks source link

select adaptive width for process bar #7

Open Unsigned-Long opened 3 months ago

Unsigned-Long commented 3 months ago
        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