1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2008 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
13 \ \\\\\\\\\\\\\\ Global Data
18 false VALUE inverse-screen?
23 false VALUE saved-cursor
26 \ \\\\\\\\\\\\\\ Structure/Implementation Dependent Methods
28 defer draw-character \ 2B inited by display driver
29 defer reset-screen \ 2B inited by display driver
30 defer toggle-cursor \ 2B inited by display driver
31 defer erase-screen \ 2B inited by display driver
32 defer blink-screen \ 2B inited by display driver
33 defer invert-screen \ 2B inited by display driver
34 defer insert-characters \ 2B inited by display driver
35 defer delete-characters \ 2B inited by display driver
36 defer insert-lines \ 2B inited by display driver
37 defer delete-lines \ 2B inited by display driver
38 defer draw-logo \ 2B inited by display driver
40 : nop-toggle-cursor ( nop ) ;
41 ' nop-toggle-cursor to toggle-cursor
43 \ \\\\\\\\\\\\\\ Implementation Independent Methods (Depend on Previous)
46 : (cursor-off) ( -- ) cursor dup to saved-cursor
47 IF toggle-cursor false to cursor THEN ;
48 : (cursor-on) ( -- ) cursor dup to saved-cursor
49 0= IF toggle-cursor true to cursor THEN ;
50 : restore-cursor ( -- ) saved-cursor dup cursor
51 <> IF toggle-cursor to cursor ELSE drop THEN ;
53 ' (cursor-off) to cursor-off
54 ' (cursor-on) to cursor-on
56 \ \\\\\\\\\\\\\\ Exported Interface:
58 \ Generic device methods:
62 \ \\\\\\\\\\\\\\ Exported Interface:
74 : get-esc-parm ( default -- value )
75 esc-num-parm dup 0> IF nip ELSE drop THEN 0 to esc-num-parm ;
76 : get-esc-parm2 ( default -- value )
77 esc-num-parm2 dup 0> IF nip ELSE drop THEN 0 to esc-num-parm2 ;
78 : set-esc-parm ( newdigit -- ) [char] 0 - esc-num-parm a * + to esc-num-parm ;
80 : reverse-cursor ( oldpos -- newpos) dup IF 1 get-esc-parm - THEN ;
81 : advance-cursor ( bound oldpos -- newpos) tuck > IF 1 get-esc-parm + THEN ;
82 : erase-in-line #columns column# - dup 0> IF delete-characters ELSE drop THEN ;
84 : terminal-line++ ( -- )
85 line# 1+ dup #lines = IF 1- 0 to line# 1 delete-lines THEN
92 0 VALUE term-background
93 7 VALUE term-foreground
96 dup d# 30 d# 39 between IF dup d# 30 - to term-foreground THEN
97 dup d# 40 d# 49 between IF dup d# 40 - to term-background THEN
102 term-foreground term-background <= to inverse?
105 : ansi-esc ( char -- )
107 dup [char] 0 [char] 9 between IF set-esc-parm
108 ELSE true to stopcsi CASE
109 [char] A OF line# reverse-cursor to line# ENDOF
110 [char] B OF #lines line# advance-cursor to line# ENDOF
111 [char] C OF #columns column# advance-cursor to column# ENDOF
112 [char] D OF column# reverse-cursor to column# ENDOF
113 [char] E OF ( FIXME: Cursor Next Line - No idea what does it mean )
114 #lines line# advance-cursor to line#
117 1 get-esc-parm2 to line# column# get-esc-parm to column#
120 1 get-esc-parm2 to line# column# get-esc-parm to column#
122 ( second parameter delimiter for f and H commands )
123 [char] ; OF false to stopcsi 0 get-esc-parm to esc-num-parm2 ENDOF
124 [char] ? OF false to stopcsi ENDOF ( FIXME: Ignore that for now )
125 [char] l OF ENDOF ( FIXME: ?25l should hide cursor )
126 [char] h OF ENDOF ( FIXME: ?25h should show cursor )
128 #lines line# - dup 0> IF
129 line# 1+ to line# delete-lines line# 1- to line#
133 [char] K OF erase-in-line ENDOF
134 [char] L OF 1 get-esc-parm insert-lines ENDOF
135 [char] M OF 1 get-esc-parm delete-lines ENDOF
136 [char] @ OF 1 get-esc-parm insert-characters ENDOF
137 [char] P OF 1 get-esc-parm delete-characters ENDOF
138 [char] m OF 0 get-esc-parm set-term-color ENDOF
139 ( These are non-ANSI commands recommended by OpenBoot )
140 [char] p OF inverse-screen? IF false to inverse-screen?
141 inverse? 0= to inverse? invert-screen
144 [char] q OF inverse-screen? 0= IF true to inverse-screen?
145 inverse? 0= to inverse? invert-screen
148 \ [char] s OF reset-screen ENDOF ( FIXME: this conflicts w. ANSI )
149 \ [char] s OF line# to saved-line# column# to saved-column# ENDOF
150 [char] u OF saved-line# to line# saved-column# to column# ENDOF
151 dup dup to dang OF blink-screen ENDOF
152 ENDCASE stopcsi IF false to csi-on
153 false to esc-on 0 to esc-num-parm 0 to esc-num-parm2 THEN
156 ( DEV VT compatibility stuff used by accept.fs )
157 [char] 7 OF line# to saved-line# column# to saved-column# ENDOF
158 [char] 8 OF saved-line# to line# saved-column# to column# ENDOF
159 [char] [ OF true to csi-on ENDOF
160 dup dup OF false to esc-on to blipp ENDOF
162 csi-on 0= IF false to esc-on THEN 0 to esc-num-parm 0 to esc-num-parm2
166 ' ansi-esc to esc-process
167 CREATE twtracebuf 4000 allot twtracebuf 4000 erase
168 twtracebuf VALUE twbp
172 twbc 4000 = IF 0 to twbc twtracebuf to twbp THEN
173 dup twbp c! twbp 1+ to twbp twbc 1+ to twbc
176 : terminal-write ( addr len -- actual-len )
180 esc-on IF esc-process
182 1B OF true to esc-on ENDOF
183 carret OF 0 to column# ENDOF
184 linefeed OF terminal-line++ ENDOF
185 bell OF blink-screen ENDOF
186 9 ( TAB ) OF column# 7 + -8 and dup #columns < IF
190 B ( VT ) OF line# ?dup IF 1- to line# THEN ENDOF
191 C ( FF ) OF 0 to line# 0 to column# erase-screen ENDOF
192 bs OF column# 1- dup 0< IF
199 to column# ( bl draw-character )
203 column# 1+ dup #columns >= IF
204 drop 0 terminal-line++