Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Standard output formatting control
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Pascal Bourguignon  
View profile  
 More options Jun 9 2006, 5:47 am
Newsgroups: comp.lang.lisp
From: Pascal Bourguignon <p...@informatimago.com>
Date: Fri, 09 Jun 2006 11:47:23 +0200
Local: Fri, Jun 9 2006 5:47 am
Subject: Re: Standard output formatting control

"phertmuller" <phertmul...@gmail.com> writes:
> My question is so simple (I guess) but I couldn't find help googleing.
> I'd like to print something (like a counter) to the standard output,
> and I'd like to fix the place where the item has to appear into the
> screen. For example, if I want to print the status of a counter, like

> (do ((x 0 (1+ x))
>        ((equal x 3))
>    (format t "x"))

> This produces

> 0
> 1
> 2

> How can I do to get these numbers in the same position ? (So, after
> printing 0, clean the output, and print the 1 in the same position).

To do this kind of thing, you have to drive the terminal.  That is,
each class of terminal understand its own protocol, special sequences
of bytes that it interprets as commands to move cursor and do some
other kind of things (change color, or other character attribute,
define zones ("windows"), move characters or lines, etc).

On a unix system, there's databases of terminal descriptions mapping
such functions to the byte sequences to be sent to the terminal:
termcap (older) or terminfo (newer).  The terminal used is indicated
by the TERM environment variable.  So you could get the content of
this variables, and read the termcap or terminfo files to collect the
byte sequences to send to move the cursor at a given position.

Or, you could use the curses (or ncurses) unix library which does that
for you.  There's the cl-curses Common Lisp package that implement the
FFI to the curses unix library.

If you use clisp, you can also use the clisp specific SCREEN package:
http://clisp.cons.org/impnotes/screen.html

(screen:with-window
  (loop for x from 0 below 3
        do (screen:set-window-cursor-position screen:*window* 4 10)
           (format screen:*window* "~4D" x)
           (sleep 1)))

Now, if you just want a quick-and-dirty solution, you can use the
Carriage Return ASCII code, in most terminal it will move the cursor
at the beginning of the line without advancing to the next line:

(loop for x from 0 below 3
      do (format t "~C~4D" (code-char 13) x)
         (sleep 1))

(it even does the right thing in emacs inferior-lisp buffers, which is
not the case of screen and other curses libraries).

Or you could use directly the byte sequences understood by your terminal.
For example, if you know your terminal understands ECMA-048 (ie. ISO6429),
then you could use:

http://darcs.informatimago.com/local/darcs/public/lisp/common-lisp/ec...

(asdf:oos 'asdf:load-op :com.informatimago.common-lisp)
(shadow '(ed))
(use-package  :com.informatimago.common-lisp.ecma048)
(generate-all-functions :compile t :verbose t :export t
                        :8-bit nil :print t :result-type 'string)
(loop for x from 0 below 3
      initially (ed 2)
      do (cup 4 10)
         (sgr (+ x 31))
         (format t "~4D" x)
         (sleep 1)
      finally (cup 22 0))

--
__Pascal Bourguignon__                     http://www.informatimago.com/

ATTENTION: Despite any other listing of product contents found
herein, the consumer is advised that, in actuality, this product
consists of 99.9999999999% empty space.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.