vt100.fs 2.37 KB
Newer Older
1 2
\ VT100.STR     VT100 excape sequences                  20may93jaw

3
\ Authors: Anton Ertl, Bernd Paysan, Neal Crook
Anton Ertl's avatar
Anton Ertl committed
4
\ Copyright (C) 1995,1999,2000,2003,2007,2012,2013,2014,2016,2018 Free Software Foundation, Inc.
anton's avatar
anton committed
5 6 7 8 9

\ This file is part of Gforth.

\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
10
\ as published by the Free Software Foundation, either version 3
anton's avatar
anton committed
11 12 13 14 15 16 17 18
\ of the License, or (at your option) any later version.

\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
\ GNU General Public License for more details.

\ You should have received a copy of the GNU General Public License
19
\ along with this program. If not, see http://www.gnu.org/licenses/.
anton's avatar
anton committed
20

21 22
decimal

23 24
[IFUNDEF] #esc  27 Constant #esc  [THEN]

25 26 27 28
: #n ( n -- )  [: 0 #s 2drop ;] #10 base-execute ;
: #n; ( n -- )  [: 0 #s 2drop ';' hold ;] #10 base-execute ;
: #esc[ ( -- ) '[' hold #esc hold ;

29
: pn    base @ swap decimal 0 u.r base ! ;
30 31
: ;pn   ';' emit pn ;
: ESC[  #esc emit '[' emit ;
32

pazsan's avatar
pazsan committed
33
: vt100-at-xy ( u1 u2 -- ) \ facility at-x-y
crook's avatar
crook committed
34 35 36
  \G Position the cursor so that subsequent text output will take
  \G place at column @var{u1}, row @var{u2} of the display. (column 0,
  \G row 0 is the top left-hand corner of the display).
37
  1+ swap 1+ <<# 'H' hold #n; #n #esc[ #0. #> type #>> ;
38

39 40 41 42 43
[IFUNDEF] at-deltaxy  Defer at-deltaxy [THEN]
: vt100-at-deltaxy ( x y -- )
    \G position the cursor relative to the current cursor position
    \G by adding @var{x} to the column and @var{y} to the row, negative
    \G numbers move up and left, positive down and right.
44
    \ over 0< over 0= and IF  drop abs backspaces  EXIT  THEN
45
    [: <<#
Bernd Paysan's avatar
Bernd Paysan committed
46
      ?dup-IF
47
	  dup 0< 'A' 'B' rot select  hold abs 0 #s 2drop #esc[
48
      THEN
Bernd Paysan's avatar
Bernd Paysan committed
49
      ?dup-IF
50
	  dup 0< 'D' 'C' rot select  hold abs 0 #s 2drop #esc[
51
      THEN #0. #> type #>> ;] #10 base-execute ;
52

pazsan's avatar
pazsan committed
53
: vt100-page ( -- ) \ facility
54 55
  \G Clear the display and set the cursor to the top left-hand
  \G corner.
56
  <<# s" [2J" holds #esc hold #0. #> type #>> 0 0 at-xy ;
57

pazsan's avatar
pazsan committed
58
' vt100-at-xy IS at-xy
59 60 61 62 63 64 65 66 67 68 69
' vt100-at-deltaxy IS at-deltaxy
' vt100-page IS page

[IFDEF] debug-out
    debug-out op-vector !
    
    ' vt100-at-xy IS at-xy
    ' vt100-at-deltaxy IS at-deltaxy
    ' vt100-page IS page
    
    default-out op-vector !
70
[THEN]