From: rnelson@ocelot.csc.wsu.edu (Roger Nelson)
Subject: Re: standards
Reply-To: rnelson@ocelot.csc.wsu.edu.UUCP ()
Organization: Washington State University
Date: Tue, 22 Dec 92 08:24:11 GMT

In article <1h5llbINNk8p@agate.berkeley.edu> bh@anarres.CS.Berkeley.EDU (Brian Harvey) writes:
>* positioned text.  (SETCURSOR x y) in character coordinates.

I have included what I use for terminal control at the end of this post.
Note that these functions have not be fully tested yet! I am posting them
only for expository purposes.

These functions are named after the corresponing ANSI escape sequences,
although I use the full name, the three character function name would be
acceptable, It would be nice if Scheme provided an aliasing feature:

Ie  (alias T_BS  TERM:BACKSPACE)


I thought I someone had done a curses like library as well as a VAX/VMS
SMG library.

>* graphics.  Simple.  (DRAW-LINE x1 y1 x2 y2) is almost enough for me.

Creating a set of functions based on an existing graphics standard
could be set up similarly.

>[Yes, I'm handwaving about this window business.  

I am currently working on a set of simple 
user interface functions that provides:

- Menus
- Windows
- Dialog boxes with the gadgets:  input text, input integer, input float,
  input s-expression, buttons, toggles, cycles, selection lists etc..

I am intending the function prototypes to be independent of text or
graphics base UI.

To define responsive user interface functions, it requires the ability to
read characters in a raw, unbuffer mode,  it would be nice if Scheme
provided an appropriate read-char function;  I.e.  (READ-CHAR-UNBUFFERED).

; terminal/ansi.scm

(define (term:BELL)              (write-char #\bel))
(define (term:BACKSPACE)         (write-char #\bs))
(define (term:HORIZONTAL_TAB)    (write-char #\ht))
(define (term:LINE_FEED)         (write-char #\nl))
(define (term:VERTICAL_TAB)      (write-char #\vt))
(define (term:FORM_FEED)         (write-char #\np))
(define (term:CARRIAGE_RETURN)   (write-char #\cr))
(define (term:SHIFT_IN)          (write-char #\si))
(define (term:SHIFT_OUT)         (write-char #\so))
(define (term:DLE)               (write-char #\dle))

(define (term:INDEX)             (write-char #\esc) (write-char #\D))
(define (term:NEXT_LINE)         (write-char #\esc) (write-char #\E))
(define (term:HORIZ_TAB_SET)     (write-char #\esc) (write-char #\H))
(define (term:REVERSE_INDEX)     (write-char #\esc) (write-char #\M))
                                              
(define (term:RESET)             (write-char #\esc) (write-char #\c))

;Control Sequences, with the number of indicated parameters.
;i.e. <CSI><parameters><control sequence letter(s)>.  Note the
;last entries consist of a space and a letter.  CSI is either
;9B or Esc[.  A minus after the number of parameters (#p)
;indicates less is valid.  Parameters are seperated by
;semicolins, e.g. Esc[14;80H sets the cursor position to row
;14, column 80.

(define (term:INSERT_CHAR count)         
     (write-char #\esc) (write-char #\[)  (display count) (write-char #@))
(define (term:CURSOR_UP count)          
     (write-char #\esc) (write-char #\[)  (display count) (write-char #\A))
(define (term:CURSOR_DOWN count)         
     (write-char #\esc) (write-char #\[)  (display count) (write-char #\B))
(define (term:CURSOR_FORWARD count)      
     (write-char #\esc) (write-char #\[)  (display count) (write-char #\C))
(define (term:CURSOR_BACKWARD count)     
     (write-char #\esc) (write-char #\[)  (display count) (write-char #\D))
(define (term:CURSOR_NEXT_LINE count)
     (write-char #\esc) (write-char #\[)  (display count) (write-char #\E))
(define (term:CURSOR_PREV_LINE count)
     (write-char #\esc) (write-char #\[)  (display count) (write-char #\F))
(define (term:CURSOR_POSITION row col)
     (write-char #\esc) (write-char #\[)  (display row)   
     (write-char #\;) (display col) (write-char #\H))
(define (term:CURSOR_HORIZ_TAB count)
     (write-char #\esc) (write-char #\[)  (display count) (write-char #\I))

(define term:ERASE_TO_END     0)
(define term:ERASE_TO_CURSOR  1)
(define term:ERASE_COMPLETELY 2)
(define (term:ERASE_IN_DISPLAY erase_mode)  
    (write-char #\esc) (write-char #\[) (display erase_mode) (write-char #\J))
(define (term:ERASE_DISPLAY)                 
    (write-char #\esc) (write-char #\[) (write-char #\f) (write-char #\esc) 
    (write-char #\[) (write-char #\J))
(define (term:ERASE_IN_LINE erase_mode)     
    (write-char #\esc) (write-char #\[) (display erase_mode) (write-char #\K))

(define (term:INSERT_LINE count)
     (write-char #\esc) (write-char #\[) (display count) (write-char #\L))
(define (term:DELETE_LINE count)
     (write-char #\esc) (write-char #\[) (display count) (write-char #\M))
(define (term:DELETE_CHAR count)
     (write-char #\esc) (write-char #\[) (display count) (write-char #\P))

(define (term:CURSOR_POSITION_REPORT arg1 arg2)
     (write-char #\esc) (write-char #\[)  (display arg1)   
     (write-char #\;) (display arg2) (write-char #\R))

; Replys with
;   Esc [ Pl ; Pc R

(define (term:SCROLL_UP count)
     (write-char #\esc) (write-char #\[) (display count) (write-char #\S))
(define (term:SCROLL_DOWN count)
     (write-char #\esc) (write-char #\[) (display count) (write-char #\T))
(define (term:CURSOR_TAB_CONTROL arg)
     (write-char #\esc) (write-char #\[) (display count) (write-char #\W))
(define (term:CURSOR_HORIZ_VERT_POSITION row col)
     (write-char #\esc) (write-char #\[) (display row) 
     (write-char #\;) (display col) (write-char #\f))
(define (term:CURSOR_BACKWARD_TAB count)
     (write-char #\esc) (write-char #\[) (display count) (write-char #\Z))
(define (term:TAB_CLEAR count)
     (write-char #\esc) (write-char #\[) (display count) (write-char #\g))

(define term:INSERT_REPLACE_MODE   "4")

(define term:KEYBOARD_ACTION_MODE  "2")
(define term:LF_NL_MODE            "20")
(define term:SCROLL_MODE           ">1")
(define term:CURSOR_KEY_MODE       "?1")

; The following are not available on the amiga console device
(define term:SEND_RECEIVE_MODE     "12")
(define term:COLUMN_MODE           "?3")
(define term:SCREEN_MODE           "?5")
(define term:WRAP_MODE             "?7")
(define term:AUTO_REPEAT_MODE      "?8")

(define (term:SET_MODE mode)
     (write-char #\esc) (write-char #\[) (display mode) (write-char #\h))
(define (term:RESET_MODE mode)
     (write-char #\esc) (write-char #\[) (display mode) (write-char #\l))

(define (term:SET_APPLICATION_KEYPAD_MODE)
     (write-char #\esc) (write-char #\=))
(define (term:SET_NUMERIC_KEYPAD_MODE)
     (write-char #\esc) (write-char #\>))

(define term:NORMAL        0)
(define term:BOLD          1)
(define term:ITALICS       3)
(define term:UNDERLINE     4)

; not available on amiga console as well as some other terminals
(define term:BLINK         5)

(define term:INVERSE       7)
(define term:NO_BOLD      21) 
(define	term:NO_ATTRIBUTE 22) ; default foreground color, not bold 
(define	term:NO_ITALICS   23)
(define	term:NO_UNDERLINE 24)
(define	term:NO_INVERSE   27)

; these names refer to the ANSI standard, not the implementation 
(define term:BLACK   30)
(define term:RED     31)
(define term:GREEN   32)
(define term:YELLOW  33)
(define term:BLUE    34)
(define term:MAGENTA 35)
(define term:CYAN    36)
(define term:WHITE   37)
(define term:DEFAULT 39)

(define term:BLACKBG     40)
(define term:REDBG       41)
(define term:GREENBG     42)
(define term:YELLOWBG    43)
(define term:BLUEBG      44)
(define term:MAGENTABG   45)
(define term:CYANBG      46)
(define term:WHITEBG     47)
(define term:DEFAULTBG   49) 
                         
;  these names refer to the implementation, they are the preferred 
;  names for use with the Amiga console device. 
(define term:CLR0 30)
(define term:CLR1 31)
(define term:CLR2 32)
(define term:CLR3 33)
(define term:CLR4 34)
(define term:CLR5 35)
(define term:CLR6 36)
(define term:CLR7 37)

(define term:CLR0BG 40)
(define term:CLR1BG 41)
(define term:CLR2BG 42)
(define term:CLR3BG 43)
(define term:CLR4BG 44)
(define term:CLR5BG 45)
(define term:CLR6BG 46)
(define term:CLR7BG 47)

(define (term:SELECT_GRAPHIC_RENDITION rendition)
     (write-char #\esc) (write-char #\[) (display rendition) (write-char #\m))

(define term:GENERAL_STATUS  "5")
(define term:PRINTER_STATUS  "?15")
(define (term:DEVICE_STATUS_REPORT status)
     (write-char #\esc) (write-char #\[) (display status) (write-char #\n))

;   Replys with :
;
;    Esc [ 0 n        Ready, no malfunction.
;
;    For term terminals
;
;    Esc [ ? 1 3 n    Printer not connected (Hasn't signaled ready).
;    Esc [ ? 1 1 n    Printer not ready to print.
;    Esc [ ? 1 0 n    Printer ready signal on.

;#ifdef AMIGA
(define (term:SET_PAGE_LENGTH length)
     (write-char #\esc) (write-char #\[) (display length) (write-char #\t))
(define (term:SET_LINE_LENGTH length)
     (write-char #\esc) (write-char #\[) (display length) (write-char #\u))
(define (term:SET_LEFT_OFFSET offset)
     (write-char #\esc) (write-char #\[) (display offset) (write-char #\x))
(define (term:SET_TOP_OFFSET offset)
     (write-char #\esc) (write-char #\[) (display offset) (write-char #\y))
(define (term:SET_RAW_EVENTS events)
     (write-char #\esc) (write-char #\[) (display events) (write-char #\{))
(define (term:RESET_RAW_EVENTS events)
     (write-char #\esc) (write-char #\[) (display events) (write-char #\}))

(define term:CURSOR_RENDITION_ON  " ")
(define term:CURSOR_RENDITION_OFF "0 ")
(define (term:SET_CURSOR_RENDITION rendition)
     (write-char #\esc) (write-char #\[) (display rendition) (write-char #\p))

(define (term:WINDOW_STATUS_REQUEST)
     (write-char #\esc) (write-char #\[) (write-char #\q))

;    ~   1     aSKR SPECIAL KEY REPORT (private Amiga Read sequence)
;    |   8     aIER INPUT EVENT REPORT (private Amiga Read sequence)
;    r   4     aWBR WINDOW BOUNDS REPORT (private Amiga Read sequence)

; /****** DSR parameters ******
;
;(define DSR_CPR    6)
;
;****** CTC parameters ******
;(define CTC_HSETTAB     0)
;(define CTC_HCLRTAB     2)
;(define CTC_HCLRTABSALL 5)
;
;******	TBC parameters ******
;(define TBC_HCLRTAB	0
;(define TBC_HCLRTABSALL	3
;

(define term:KEY_UP                400)
(define term:KEY_DOWN              401)
(define term:KEY_RIGHT             402)
(define term:KEY_LEFT              403)
(define term:KP_ENTER              404)
(define term:KP_PF1                405)
(define term:KP_PF2                406)
(define term:KP_PF3                407)
(define term:KEY_SHIFT_DOWN        408)
(define term:KP_PF4                409)
(define term:KEY_SHIFT_UP          410)
(define term:KP_COMMA              411)
(define term:KP_MINUS              412)
(define term:KP_PERIOD             413)
(define term:KP_0                  414)
(define term:KP_1                  415)
(define term:KP_2                  416)
(define term:KP_3                  417)
(define term:KP_4                  418)
(define term:KP_5                  419)
(define term:KP_6                  420)
(define term:KP_7                  421)
(define term:KP_8                  422)
(define term:KP_9                  423)
(define term:KEY_SHIFT_LEFT        424)
(define term:KEY_SHIFT_RIGHT       425)
(define term:KEY_SHIFT_F1          427)
(define term:KEY_SHIFT_F2          428)
(define term:KEY_SHIFT_F3          429)
(define term:KEY_SHIFT_F4          430)
(define term:KEY_SHIFT_F5          431)
(define term:KEY_SHIFT_F6          432)
(define term:KEY_SHIFT_F7          433)
(define term:KEY_SHIFT_F8          434)
(define term:KEY_SHIFT_F9          435)
(define term:KEY_SHIFT_F10         436)
(define term:KEY_F1                426)
(define term:KEY_F2                437)
(define term:KEY_F3                438)
(define term:KEY_F4                439)
(define term:KEY_F5                440)
(define term:KEY_F6                441)
(define term:KEY_F7                442)
(define term:KEY_F8                443)
(define term:KEY_F9                444)
(define term:KEY_F10               445)
(define term:KEY_HELP              446)
(define term:KEY_APPL_UP           447)
(define term:KEY_APPL_DOWN         448)
(define term:KEY_APPL_RIGHT        449)
(define term:KEY_APPL_LEFT         450)
(define term:KEY_SHIFT_APPL_DOWN   451)
(define term:KEY_SHIFT_APPL_UP     452)



_____________________________________________________________________
      ______________
____  | ^          |    Roger Nelson          rnelson@wsuaix.csc.wsu.edu
\^^ |*| ^          |    Agricultural Engineering Department     ///
 |^^//  ^^         |                                           ///
 |  '  ^          +|    Washington State University        \\\///
 \_  ^    _________|    Pullman, WA 99164                   \XX/
   `-----'              Work: (509)335-4714  Home: (509)332-8387