unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: Set debug output width in REPL
Date: Sat, 26 Feb 2011 04:17:57 -0500	[thread overview]
Message-ID: <87aahjupbu.fsf@netris.org> (raw)
In-Reply-To: <87bp21qagc.fsf@gnu.org> ("Ludovic Courtès"'s message of "Fri, 25 Feb 2011 00:28:19 +0100")

ludo@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



  reply	other threads:[~2011-02-26  9:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-21 22:55 Set debug output width in REPL Mike Gran
2011-02-24 23:28 ` Ludovic Courtès
2011-02-26  9:17   ` Mark H Weaver [this message]
2011-03-05 19:18   ` Mark H Weaver
  -- strict thread matches above, loose matches on Subject: below --
2011-02-25  1:43 Mike Gran
2011-02-21  6:02 Mike Gran
2011-02-21 16:12 ` Mark H Weaver
2011-02-21 16:36   ` Mark H Weaver
2011-03-04 10:17 ` Andy Wingo
2011-03-05 13:26   ` Ludovic Courtès
2011-03-05 19:01     ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87aahjupbu.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).