From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: Set debug output width in REPL Date: Sat, 26 Feb 2011 04:17:57 -0500 Message-ID: <87aahjupbu.fsf@netris.org> References: <309828.81527.qm@web37907.mail.mud.yahoo.com> <87bp21qagc.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1298711928 26541 80.91.229.12 (26 Feb 2011 09:18:48 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 26 Feb 2011 09:18:48 +0000 (UTC) Cc: guile-devel@gnu.org To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Feb 26 10:18:41 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PtGIT-0005T7-2A for guile-devel@m.gmane.org; Sat, 26 Feb 2011 10:18:41 +0100 Original-Received: from localhost ([127.0.0.1]:55277 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PtGIS-0006N4-GB for guile-devel@m.gmane.org; Sat, 26 Feb 2011 04:18:40 -0500 Original-Received: from [140.186.70.92] (port=35501 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PtGIF-0006ME-1i for guile-devel@gnu.org; Sat, 26 Feb 2011 04:18:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PtGIA-0004gg-6X for guile-devel@gnu.org; Sat, 26 Feb 2011 04:18:26 -0500 Original-Received: from world.peace.net ([216.204.32.208]:34998) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PtGI4-0004f5-Oo; Sat, 26 Feb 2011 04:18:16 -0500 Original-Received: from c-98-217-70-13.hsd1.ma.comcast.net ([98.217.70.13] helo=freedomincluded) by world.peace.net with esmtpa (Exim 4.69) (envelope-from ) id 1PtGHo-0002Uz-Qx; Sat, 26 Feb 2011 04:18:00 -0500 Original-Received: from mhw by freedomincluded with local (Exim 4.69) (envelope-from ) id 1PtGHn-0002Wl-2g; Sat, 26 Feb 2011 04:17:59 -0500 In-Reply-To: <87bp21qagc.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Fri, 25 Feb 2011 00:28:19 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 216.204.32.208 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11720 Archived-At: ludo@gnu.org (Ludovic Court=C3=A8s) writes: >> [...] If one wanted to have a port automatically >> query its terminal for the width, one could either (IIRC) catch the SIGW= INCH >> signalor could call a getenv/tget function before printing a pretty-prin= t or >> truncated-print. > > How about having a per-REPL setting that=E2=80=99s automatically set to t= he > terminal=E2=80=99s width by default? > > What=E2=80=99s 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 #endif #if GWINSZ_IN_SYS_IOCTL # include #endif #ifdef TIOCGWINSZ struct winsize ws; if (ioctl(term_file_descriptor, TIOCGWINSZ, &ws) < 0) ERROR; terminal_width =3D ws.ws_col; #endif Ideally this code would be called not only during initialization, but also in response to the SIGWINCH signal. Best, Mark