[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Set debug output width in REPL
From: |
Mark H Weaver |
Subject: |
Re: Set debug output width in REPL |
Date: |
Sat, 26 Feb 2011 04:17:57 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
address@hidden (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