unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Re: Set debug output width in REPL
@ 2011-02-21 22:55 Mike Gran
  2011-02-24 23:28 ` Ludovic Courtès
  0 siblings, 1 reply; 11+ messages in thread
From: Mike Gran @ 2011-02-21 22:55 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-devel

> From:Mark H Weaver <mhw@netris.org>

> 
> Mark wrote:
> > It seems to me that *width* should not be a global variable, but rather
> > a per-repl setting.  It probably belongs in the options field of the
> > <repl> record, no?  See "repl-default-options" in 
> repl/common.scm.

For my personal case, when I run the REPL, I run it in a single terminal.
When new REPLs are spawned, they are recursive.  If we implemented such
a patch, it might make sense to have children inherit the width of their
parents.

How common is the use case where REPLs for a single Guile session appear
in terminals of different width?

> 
> Mark also wrote:
> Better yet, maybe it should be an optional attribute of the output port,
> which would allow pretty-print and truncated-print to use it as well.
> Output ports attached to terminals could determine the terminal width
> from the OS, on systems that support it.

This would also work, but, the width of terminals can change when windows
are resized.  So, updating that attribute would either have to be a manual
call to query the width and update it or it'd have to try to automatically
query the terminal for the width.  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.

> 
> What do you think?

The important thing for me is to be able to spread backtrace
information over a couple of terminal lines, so I'd like to be able to set
a default width that is greater than the terminal width.

Thanks,

Mike



^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: Set debug output width in REPL
@ 2011-02-25  1:43 Mike Gran
  0 siblings, 0 replies; 11+ messages in thread
From: Mike Gran @ 2011-02-25  1:43 UTC (permalink / raw)
  To: Ludovic Courtès, guile-devel@gnu.org

> From:Ludovic Courtès <ludo@gnu.org>
> 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?

The lightweight way is to just check for the COLUMNS environment variable.
Most of the xterm-like terminals set COLUMNS when a program is executed.
That will cover most situations when running in X.

Beyond that, you'd need to look at the TERM variable and guess columns
from that.  For this you'd usually query the terminfo database, which means
that you probably end up with curses as a dependency.  It usually already
is, since readline depends on it.

Below please find a program that uses curses to find the terminal's
width.  It needs to be linked -lcurses.

Alternately you could execute "tput cols".

Thanks,

-Mike

#include <stdio.h>
#include <curses.h>
#include <term.h>
#define STDOUT_FILENO 1
#define DEFAULT_COLUMNS (80)
int main (int argc, char ** argv)
{
  int ret, err, cols;
  setupterm ((char *) 0, STDOUT_FILENO, &err);
  if (ret == OK || err == 1)
    {
      cols = tigetnum ("cols");
      if (cols < 0)
        cols = DEFAULT_COLUMNS;
    }
  else
    cols = DEFAULT_COLUMNS;
  printf("columns %d\n", cols);
  return 0;
}




^ permalink raw reply	[flat|nested] 11+ messages in thread
* Set debug output width in REPL
@ 2011-02-21  6:02 Mike Gran
  2011-02-21 16:12 ` Mark H Weaver
  2011-03-04 10:17 ` Andy Wingo
  0 siblings, 2 replies; 11+ messages in thread
From: Mike Gran @ 2011-02-21  6:02 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 205 bytes --]

Hi-

I find that the backtrace output in the REPL is too constrained
my verbose code.  The attached patch would let one set the 

width of the backtrace and locals meta-commands.

What do you think?

-Mike

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-width-meta-command-to-set-screen-width-in-debug-.patch --]
[-- Type: text/x-patch; name="0001-Add-width-meta-command-to-set-screen-width-in-debug-.patch", Size: 3123 bytes --]

From 781bcc2783709e76591cd354f4976f02eb284526 Mon Sep 17 00:00:00 2001
From: Michael Gran <spk121@yahoo.com>
Date: Sun, 20 Feb 2011 21:53:46 -0800
Subject: [PATCH] Add ,width meta-command to set screen width in debug output

This meta-command allows one to set the default number of columns
that output from ,backtrace and ,locals shall occupy.

* doc/ref/scheme-using.texi (Debug Commands): document ,width
* module/system/repl/command.scm (*width*): new var
  (backtrace, locals): use *width* in optarg
  (width): new meta-command
---
 doc/ref/scheme-using.texi      |    6 ++++++
 module/system/repl/command.scm |   21 ++++++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/doc/ref/scheme-using.texi b/doc/ref/scheme-using.texi
index 126b845..a119d42 100644
--- a/doc/ref/scheme-using.texi
+++ b/doc/ref/scheme-using.texi
@@ -337,6 +337,12 @@ Show the VM registers associated with the current frame.
 @xref{Stack Layout}, for more information on VM stack frames.
 @end deffn
 
+@deffn {REPL Command} width [cols]
+Sets the number of display columns in the output of @code{,backtrace}
+and @code{,locals} to @var{cols}.  If @var{cols} is not given, the width
+of the terminal is used.
+@end deffn
+
 The next 3 commands work at any REPL.
 
 @deffn {REPL Command} break proc
diff --git a/module/system/repl/command.scm b/module/system/repl/command.scm
index d4b3e4a..40d720d 100644
--- a/module/system/repl/command.scm
+++ b/module/system/repl/command.scm
@@ -71,6 +71,8 @@
 (define *show-table*
   '((show (warranty w) (copying c) (version v))))
 
+(define *width* 72)
+
 (define (group-name g) (car g))
 (define (group-commands g) (cdr g))
 
@@ -546,7 +548,7 @@ Trace execution."
                  (format #t "Nothing to debug.~%"))))))))
 
 (define-stack-command (backtrace repl #:optional count
-                                 #:key (width 72) full?)
+                                 #:key (width *width*) full?)
   "backtrace [COUNT] [#:width W] [#:full? F]
 Print a backtrace.
 
@@ -626,12 +628,12 @@ With an argument, select a frame by index, then show it."
 Print the procedure for the selected frame."
   (repl-print repl (frame-procedure cur)))
 
-(define-stack-command (locals repl)
+(define-stack-command (locals repl #:key (width *width*))
   "locals
 Show local variables.
 
 Show locally-bound variables in the selected frame."
-  (print-locals cur))
+  (print-locals cur #:width width))
 
 (define-stack-command (error-message repl)
   "error-message
@@ -811,6 +813,19 @@ Print registers.
 Print the registers of the current frame."
   (print-registers cur))
 
+(define-meta-command (width repl #:optional x)
+  "width [X]
+Set debug output width.
+
+Set the number of screen columns in the output from `backtrace' and
+`locals'."
+  (if (and x (not (integer? x)))
+      (error "expected a column number (a non-negative integer)" x)
+      (let ((w (or x
+                   (false-if-exception (string->number (getenv "COLUMNS")))
+                   72)))
+        (format #t "Setting screen width to ~a columns~%" w)
+        (set! *width* w))))
 
 \f
 ;;;
-- 
1.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-03-05 19:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).