l...@gnu.org (Ludovic Courtès) writes: >> [...] If one wanted to have a port automatically >> query its terminal for the width, one could either (IIRC) catch the SIGWINCH >> signalor could call a getenv/tget function before printing a pretty-print or >> truncated-print. > > How about having a per-REPL setting that’s automatically set to the > terminal’s width by default? > > What’s the exact call to get the width?
There's an ioctl (TIOCGWINSZ) that queries the kernel's idea of the terminal size. See the autoconf macro AC_HEADER_TIOCGWINSZ and the gnulib modules winsz-ioctl and winsz-termios. Search for TIOCGWINSZ and SIGWINCH in various packages (e.g. openssh and ncurses) to see how they do it. This is the rough idea: AC_CHECK_HEADERS([termios.h]) AC_HEADER_TIOCGWINSZ #if HAVE_TERMIOS_H # include <termios.h> #endif #if GWINSZ_IN_SYS_IOCTL # include <sys/ioctl.h> #endif #ifdef TIOCGWINSZ struct winsize ws; if (ioctl(term_file_descriptor, TIOCGWINSZ, &ws) < 0) ERROR; terminal_width = ws.ws_col; #endif Ideally this code would be called not only during initialization, but also in response to the SIGWINCH signal. Best, Mark