Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!gatech!nntp.msstate.edu!night.primate.wisc.edu!aplcenmp!hall
From: hall@aplcenmp.apl.jhu.edu (Marty Hall)
Subject: Re: "Clear screen / goto (x,y).. please help
Message-ID: <D7x1Ir.DrC@aplcenmp.apl.jhu.edu>
Organization: JHU/APL AI Lab, Hopkins P/T CS Faculty
References: <3nuusl$rsk@harbinger.cc.monash.edu.au>
Date: Mon, 1 May 1995 20:13:38 GMT
Lines: 58

In article <3nuusl$rsk@harbinger.cc.monash.edu.au> mpsoy1@mdw053.cc.monash.edu.au (Mr MP Soysa) writes:
>Could some one please tell me the format directives or
>commands to move the cursor to some point in the screen
>or alternatively to clear the screen and go to the top ?

This depends on your terminal type. You can just generate and print
the ESC sequences your terminal wants. Eg here are two simple examples
that work on a VT200 that I made for my students. I'm not aware of a
curses-like interface that works for multiple terminal types or that
tries to parse the /etc/termcap file (on UNIX). I use the nonstandard
#\Escape, which several Lisps support. You could use (code-char 27)
instead, assuming ASCII.

;;; Operation		Command
;;; ================+================
;;; Clear Screen        ESC[2JESC[H
;;; Up N lines          ESC[NA       ; N is a variable
;;; Down N lines        ESC[NB       ; N is a variable
;;; Right N cols        ESC[NC       ; N is a variable
;;; Left N cols		ESC[ND       ; N is a variable
;;; Move cursor to
;;;   line L, col C     ESC[L;CH     ; L, C are variables
;;;
;;; Note that #\Escape is the character for ESC in Lisp; you
;;; can use (setf (aref <String> <Position>) #\Escape) to stick it in, or
;;; use (format nil ...) to construct the string. See two examples below,
;;; one doing it each way.
;;; 1995 Marty Hall. marty_hall@jhuapl.edu
;;;======================================================================

;;;======================================================================
;;; Defines a Clear-Screen function for vt100 terminals.
;;; Note that this does not work if running Lisp within emacs, only
;;; from a tty in vtxxx mode. You could put a real escape character in
;;; the file instead of sticking it in the string at run-time, but that
;;; would make it hard to view and print the source code.

(defun Clear-Screen ()
  "Clear the screen on a vt100 terminal. Don't use from within emacs."
  (let ((String " [2J [H"))
    (setf (aref String 0) #\Escape)   ; Stick ESCAPE in for the spaces
    (setf (aref String 4) #\Escape)
    (princ String)                    ; PRINC doesn't do a CR (PRINT does)
    (values) ))
    
;;;======================================================================
;;; Again, don't use this from within emacs.

(defun Move-Up (Lines)
  "On a vt100 terminal, move cursor up the specified number of lines"
  (let ((String (format nil "~A[~DA" #\Escape Lines)))  ; ie "ESC[3A"
    (format t String)
    (values)))                                          ; Suppress output

;;;======================================================================

					- Marty
(proclaim '(inline skates))
