author | Claus Gittinger <cg@exept.de> |
Fri, 24 May 2013 16:36:24 +0200 | |
changeset 4221 | 78dfbf10887b |
parent 2782 | da507ebdf37d |
child 4269 | edb108492a92 |
permissions | -rw-r--r-- |
1361 | 1 |
" |
2 |
COPYRIGHT (c) 1998 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
2076 | 12 |
"{ Package: 'stx:libwidg2' }" |
13 |
||
930 | 14 |
TerminalView subclass:#VT100TerminalView |
998 | 15 |
instanceVariableNames:'currentParam parameters lastCursorLine' |
920 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Views-TerminalViews' |
|
19 |
! |
|
20 |
||
927 | 21 |
!VT100TerminalView class methodsFor:'documentation'! |
22 |
||
2116 | 23 |
ansiEscapes |
24 |
" |
|
25 |
ANSI ESCAPE SEQUENCES |
|
26 |
=============================================================================== |
|
27 |
Wherever you see '#', that should be replaced by the appropriate number. |
|
28 |
||
29 |
ESC code sequence Function |
|
30 |
------------------- --------------------------- |
|
31 |
Cursor Controls: |
|
32 |
ESC[#;#H or ESC[#;#f Moves cusor to line #, column # |
|
33 |
ESC[#A Moves cursor up # lines |
|
34 |
ESC[#B Moves cursor down # lines |
|
35 |
ESC[#C Moves cursor forward # spaces |
|
36 |
ESC[#D Moves cursor back # spaces |
|
37 |
ESC[#;#R Reports current cursor line & column |
|
38 |
ESC[s Saves cursor position for recall later |
|
39 |
ESC[u Return to saved cursor position |
|
40 |
||
41 |
Erase Functions: |
|
42 |
ESC[2J Clear screen and home cursor |
|
43 |
ESC[K Clear to end of line |
|
44 |
||
45 |
Set Graphics Rendition: |
|
46 |
ESC[#;#;....;#m Set display attributes where # is |
|
47 |
0 for normal display |
|
48 |
1 for bold on |
|
49 |
4 underline (mono only) |
|
50 |
5 blink on |
|
51 |
7 reverse video on |
|
52 |
8 nondisplayed (invisible) |
|
53 |
30 black foreground |
|
54 |
31 red foreground |
|
55 |
32 green foreground |
|
56 |
33 yellow foreground |
|
57 |
34 blue foreground |
|
58 |
35 magenta foreground |
|
59 |
36 cyan foreground |
|
60 |
37 white foreground |
|
61 |
40 black background |
|
62 |
41 red background |
|
63 |
42 green background |
|
64 |
43 yellow background |
|
65 |
44 blue background |
|
66 |
45 magenta background |
|
67 |
46 cyan background |
|
68 |
47 white background |
|
69 |
||
70 |
ESC[=#;7h or Put screen in indicated mode where # is |
|
71 |
ESC[=h or 0 for 40 x 25 black & white |
|
72 |
ESC[=0h or 1 for 40 x 25 color |
|
73 |
ESC[?7h 2 for 80 x 25 b&w |
|
74 |
3 for 80 x 25 color |
|
75 |
4 for 320 x 200 color graphics |
|
76 |
5 for 320 x 200 b & w graphics |
|
77 |
6 for 640 x 200 b & w graphics |
|
78 |
7 to wrap at end of line |
|
79 |
||
80 |
ESC[=#;7l or ESC[=l or Resets mode # set with above command |
|
81 |
ESC[=0l or ESC[?7l |
|
82 |
||
83 |
Keyboard Reassignments: |
|
84 |
ESC[#;#;...p Keyboard reassignment. The first ASCII |
|
85 |
or ESC[""string""p code defines which code is to be |
|
86 |
or ESC[#;""string"";#; changed. The remaining codes define |
|
87 |
#;""string"";#p what it is to be changed to. |
|
88 |
||
89 |
E.g. Reassign the Q and q keys to the A and a keys (and vice versa). |
|
90 |
ESC [65;81p A becomes Q |
|
91 |
ESC [97;113p a becomes q |
|
92 |
ESC [81;65p Q becomes A |
|
93 |
ESC [113;97p q becomes a |
|
94 |
||
95 |
E.g. Reassign the F10 key to a DIR command. |
|
96 |
ESC [0;68;""dir"";13p The 0;68 is the extended ASCII code |
|
97 |
for the F10 key and 13 is the ASCII |
|
98 |
code for a carriage return. |
|
99 |
||
100 |
Other function key codes F1=59,F2=60,F3=61,F4=62,F5=63 |
|
101 |
F6=64,F7=65,F8=66,F9=67,F10=68 |
|
102 |
" |
|
103 |
! |
|
104 |
||
1361 | 105 |
copyright |
106 |
" |
|
107 |
COPYRIGHT (c) 1998 by eXept Software AG |
|
108 |
All Rights Reserved |
|
109 |
||
110 |
This software is furnished under a license and may be used |
|
111 |
only in accordance with the terms of that license and with the |
|
112 |
inclusion of the above copyright notice. This software may not |
|
113 |
be provided or otherwise made available to, or used by, any |
|
114 |
other person. No title to or ownership of the software is |
|
115 |
hereby transferred. |
|
116 |
" |
|
117 |
||
118 |
||
119 |
! |
|
120 |
||
927 | 121 |
documentation |
122 |
" |
|
1418 | 123 |
A VT100 terminal emulator. |
124 |
Most of the functionality is inherited from my superclass, |
|
125 |
I redefine/specialize certain methods for VT100 escape sequences |
|
126 |
and vt100 keyboard codes |
|
927 | 127 |
|
1419 | 128 |
BUGS: |
129 |
VT100 wrapMode (at right margin) is not supported |
|
130 |
this may lead to wrong display when a vi is started in a small window. |
|
131 |
||
927 | 132 |
[start with:] |
133 |
VT100TerminalView openShell |
|
1418 | 134 |
|
135 |
[see also:] |
|
136 |
VT52TerminalView |
|
137 |
TelnetTool |
|
927 | 138 |
" |
139 |
||
140 |
||
141 |
! ! |
|
920 | 142 |
|
932 | 143 |
!VT100TerminalView methodsFor:'defaults'! |
927 | 144 |
|
145 |
vt100KeyCodes |
|
1420 | 146 |
"return a vt100 keyCode table" |
147 |
||
927 | 148 |
^ IdentityDictionary withKeysAndValues: |
149 |
#( |
|
150 |
#CursorUp '\e[A' |
|
151 |
#CursorDown '\e[B' |
|
152 |
#CursorRight '\e[C' |
|
153 |
#CursorLeft '\e[D' |
|
154 |
#Home '\e[H' |
|
155 |
#Escape '\e' |
|
156 |
#BackSpace '\b' |
|
157 |
#Return '\r' |
|
976 | 158 |
#Delete '\0177' |
1357 | 159 |
#Tab '\t' |
1352 | 160 |
|
161 |
#F1 '\eOP' |
|
162 |
#F2 '\eOQ' |
|
163 |
#F3 '\eOR' |
|
164 |
#F4 '\eOS' |
|
165 |
#F5 '\eOt' |
|
166 |
#F6 '\eOu' |
|
167 |
#F7 '\eOv' |
|
168 |
#F8 '\eOl' |
|
169 |
#F9 '\eOw' |
|
927 | 170 |
) |
171 |
||
172 |
"Created: / 10.6.1998 / 15:13:01 / cg" |
|
1357 | 173 |
"Modified: / 5.5.1999 / 15:01:32 / cg" |
927 | 174 |
! ! |
175 |
||
176 |
!VT100TerminalView methodsFor:'functions'! |
|
177 |
||
178 |
addLines |
|
1420 | 179 |
"Add the appropriate number of blank lines (param 1) |
180 |
at the cursor position." |
|
927 | 181 |
|
1420 | 182 |
self addLines:((parameters at:1) max:1). |
927 | 183 |
self endOfSequence |
184 |
||
185 |
"Created: / 10.6.1998 / 14:48:03 / cg" |
|
186 |
! |
|
187 |
||
1420 | 188 |
addLines:aNumber |
927 | 189 |
"Add aNumber blank lines at the position indicated by the cursor." |
190 |
||
1420 | 191 |
aNumber timesRepeat:[ |
927 | 192 |
self insertLine:'' before:cursorLine |
193 |
] |
|
194 |
||
195 |
"Created: / 10.6.1998 / 14:49:30 / cg" |
|
196 |
! |
|
197 |
||
949 | 198 |
autoMargin:aBoolean |
199 |
"set/clear autowrap at end of line (not yet implemented)" |
|
200 |
||
2268 | 201 |
autoWrapFlag := aBoolean |
949 | 202 |
! |
203 |
||
2192 | 204 |
clearLines:arg |
1420 | 205 |
"Clear some part of the current line, as indicated by the first parameter: |
206 |
0 - clear to EOL |
|
207 |
1 - clear from beginning to cursorCol |
|
208 |
2 - clear entire line |
|
209 |
" |
|
927 | 210 |
|
1001
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
211 |
arg = 0 ifTrue: [^self doClearToEndOfLine]. |
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
212 |
arg = 1 ifTrue: [^self doClearFromBeginningOfLine]. |
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
213 |
arg = 2 ifTrue: [^self doClearEntireLine] |
927 | 214 |
|
215 |
"Created: / 10.6.1998 / 14:44:22 / cg" |
|
1001
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
216 |
"Modified: / 21.7.1998 / 20:07:42 / cg" |
927 | 217 |
! |
218 |
||
949 | 219 |
deleteCharacters |
1420 | 220 |
"Delete the appropriate number of characters (param 1) |
221 |
at the cursor position." |
|
949 | 222 |
|
223 |
|n| |
|
224 |
||
225 |
n := ((parameters at: 1) max: 1). |
|
226 |
self deleteFromLine:cursorLine col:cursorCol toLine:cursorLine col:cursorCol+n-1. |
|
227 |
||
228 |
"Created: / 12.6.1998 / 21:19:02 / cg" |
|
229 |
"Modified: / 12.6.1998 / 21:19:15 / cg" |
|
230 |
! |
|
231 |
||
2192 | 232 |
displayMode:p1 |
1420 | 233 |
"Set the current display mode (emphasis) as specified by param 1." |
927 | 234 |
|
2192 | 235 |
|clrName| |
1352 | 236 |
|
237 |
||
1020 | 238 |
"/ self endEntry. |
1352 | 239 |
p1 == 1 ifTrue:[ |
951 | 240 |
"/ ESC-[-1-m -> bold |
241 |
||
1287
48e6c847a554
use red color instead of bold
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
242 |
"/ workaround: windows bold fonts are |
48e6c847a554
use red color instead of bold
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
243 |
"/ wider, leading to ugly looking output |
48e6c847a554
use red color instead of bold
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
244 |
"/ Therefore, use red color instead of bold |
1667 | 245 |
device platformName = 'WIN32' ifTrue:[ |
1287
48e6c847a554
use red color instead of bold
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
246 |
self color:Color red. |
48e6c847a554
use red color instead of bold
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
247 |
] ifFalse:[ |
48e6c847a554
use red color instead of bold
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
248 |
self bold. |
48e6c847a554
use red color instead of bold
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
249 |
]. |
951 | 250 |
^ self. |
251 |
]. |
|
1352 | 252 |
p1 == 4 ifTrue:[ |
253 |
"/ ESC-[-4-m -> underline |
|
254 |
||
255 |
self underline. |
|
256 |
^ self. |
|
257 |
]. |
|
258 |
p1 == 5 ifTrue:[ |
|
259 |
"/ ESC-[-5-m -> blink |
|
260 |
||
261 |
self color:Color blue. |
|
262 |
^ self. |
|
263 |
]. |
|
264 |
p1 == 7 ifTrue:[ |
|
265 |
"/ ESC-[-7-m -> reverse |
|
951 | 266 |
|
978 | 267 |
self reverse. |
268 |
^ self. |
|
269 |
]. |
|
2116 | 270 |
p1 == 8 ifTrue:[ |
271 |
"/ ESC-[-8-m -> invisible |
|
272 |
^ self. |
|
273 |
]. |
|
274 |
(p1 between:30 and:37) ifTrue:[ |
|
275 |
"/ ESC-[-30-m -> black fg color |
|
276 |
"/ ESC-[-31-m -> red fg color |
|
277 |
"/ ... |
|
278 |
"/ ESC-[-37-m -> white fg color |
|
279 |
clrName := #(black red green yellow blue magenta cyan white) at:(p1-30+1). |
|
280 |
self color:(Color perform:clrName). |
|
281 |
^ self. |
|
282 |
]. |
|
283 |
(p1 between:40 and:47) ifTrue:[ |
|
284 |
"/ ESC-[-40-m -> black bg color |
|
285 |
"/ ... |
|
286 |
"/ ESC-[-47-m -> white bg color |
|
287 |
clrName := #(black red green yellow blue magenta cyan white) at:(p1-40+1). |
|
288 |
self bgColor:(Color perform:clrName). |
|
289 |
^ self. |
|
290 |
]. |
|
1020 | 291 |
|
978 | 292 |
"/ ESC-[-any-m -> normal |
293 |
self normal. |
|
927 | 294 |
|
295 |
"Created: / 10.6.1998 / 15:01:16 / cg" |
|
1352 | 296 |
"Modified: / 5.5.1999 / 00:53:15 / cg" |
927 | 297 |
! |
298 |
||
2192 | 299 |
doClearDisplay:arg |
1420 | 300 |
"Clear some part of the current screen, as indicated by the first parameter. |
301 |
0 - clear to endOfScreen |
|
302 |
1 - clear from beginning of screen to cursorCol |
|
303 |
2 - clear entire screen |
|
304 |
" |
|
1001
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
305 |
|
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
306 |
arg = 0 ifTrue: [^self doClearToEndOfScreen]. |
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
307 |
arg = 1 ifTrue: [^self doClearFromBeginningOfScreen]. |
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
308 |
arg = 2 ifTrue: [^self doClearEntireScreen] |
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
309 |
|
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
310 |
"Created: / 21.7.1998 / 20:05:07 / cg" |
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
311 |
"Modified: / 21.7.1998 / 20:07:36 / cg" |
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
312 |
! |
7fe14ad43ae3
fixed clear-to-end-of-screen function.
Claus Gittinger <cg@exept.de>
parents:
998
diff
changeset
|
313 |
|
1020 | 314 |
insertCharacters |
1420 | 315 |
"Insert the appropriate number of spaces (param 1) at the cursor position." |
949 | 316 |
|
317 |
|s| |
|
318 |
||
319 |
s := String new:((parameters at: 1) max: 1). |
|
1420 | 320 |
self insertStringWithoutCRs:s atLine:cursorLine col:cursorCol. |
949 | 321 |
|
322 |
"Modified: / 12.6.1998 / 21:14:25 / cg" |
|
1020 | 323 |
"Created: / 28.7.1998 / 00:53:51 / cg" |
949 | 324 |
! |
325 |
||
927 | 326 |
move |
327 |
"Move to the locations indicated by the first and second parameters." |
|
328 |
||
2217 | 329 |
| row column | |
330 |
||
331 |
row := (self getParameter:1 withDefault:1). |
|
332 |
column := (self getParameter:2 withDefault:1). |
|
2202 | 333 |
Debug ifTrue:[ |
2217 | 334 |
Transcript show:'move to column/row:'; show:column; show:'/'; showCR:row. |
335 |
]. |
|
336 |
self moveToX:column y:row. |
|
927 | 337 |
|
338 |
"Created: / 10.6.1998 / 14:40:01 / cg" |
|
978 | 339 |
"Modified: / 20.6.1998 / 18:49:12 / cg" |
927 | 340 |
! |
341 |
||
342 |
moveToX: xLocation y: yLocation |
|
343 |
"Position the cursor at the location given by xLocation and yLocation. |
|
344 |
Ignore the command if the parameters are outside the allowable range." |
|
345 |
||
2192 | 346 |
Debug ifTrue:[ |
347 |
Transcript show:'numberOfColumns '; showCR:numberOfColumns. |
|
348 |
Transcript show:'numberOfLines '; showCR:numberOfLines. |
|
349 |
]. |
|
978 | 350 |
"/ (xLocation < 1 or: [xLocation > numberOfColumns]) ifTrue: [^self]. |
351 |
"/ (yLocation < 1 or: [yLocation > numberOfLines]) ifTrue: [^self]. |
|
952 | 352 |
|
949 | 353 |
self cursorVisibleLine:yLocation col:xLocation. |
927 | 354 |
|
355 |
"Created: / 10.6.1998 / 14:40:49 / cg" |
|
978 | 356 |
"Modified: / 20.6.1998 / 20:27:11 / cg" |
927 | 357 |
! |
358 |
||
944 | 359 |
reportTerminalType |
1420 | 360 |
"currently, only cursor position is supported (param 6)" |
361 |
||
944 | 362 |
(parameters at: 1) == 6 ifTrue:[ |
363 |
"/ report position |
|
1020 | 364 |
self endEntry. |
365 |
||
944 | 366 |
inStream nextPut:(Character esc). |
367 |
inStream nextPutAll:'[' |
|
368 |
, cursorLine printString |
|
369 |
, ';' |
|
370 |
, cursorCol printString |
|
371 |
, 'R'. |
|
372 |
^ self |
|
373 |
]. |
|
374 |
(parameters at: 1) == 7 ifTrue:[ |
|
375 |
"/ display name |
|
376 |
]. |
|
377 |
||
378 |
"Created: / 11.6.1998 / 23:05:50 / cg" |
|
1020 | 379 |
"Modified: / 28.7.1998 / 00:54:30 / cg" |
944 | 380 |
! |
381 |
||
927 | 382 |
resetDefaults |
383 |
"Reset the default parameters" |
|
384 |
||
2192 | 385 |
|l1 l2| |
949 | 386 |
|
978 | 387 |
|
949 | 388 |
l1 := (parameters at: 1). |
389 |
l2 := (parameters at: 2). |
|
2192 | 390 |
Debug ifTrue:[ |
391 |
Transcript show:'resetDefaults:'; show:l1;show:' ';showCR:l2. |
|
392 |
]. |
|
949 | 393 |
(l1 ~~ 0 and:[l2 ~~ 0]) ifTrue:[ |
394 |
rangeStartLine := l1. |
|
395 |
rangeEndLine := l2. |
|
396 |
] ifFalse:[ |
|
978 | 397 |
"/ self halt. |
949 | 398 |
]. |
399 |
||
978 | 400 |
"/ (rangeStartLine == 1 and:[rangeEndLine == numberOfLines]) ifTrue:[ |
401 |
"/ rangeEndLine := rangeStartLine := nil. |
|
402 |
"/ ]. |
|
403 |
||
404 |
"/ autoLineFeed := false. |
|
405 |
"/ autoMargin := true. |
|
406 |
"/ displayMode := 0. "Normal display"!! !! |
|
927 | 407 |
|
408 |
"Created: / 10.6.1998 / 14:50:53 / cg" |
|
978 | 409 |
"Modified: / 20.6.1998 / 20:28:26 / cg" |
920 | 410 |
! ! |
411 |
||
412 |
!VT100TerminalView methodsFor:'initialization'! |
|
413 |
||
927 | 414 |
initialize |
415 |
super initialize. |
|
949 | 416 |
|
2268 | 417 |
autoWrapFlag := true. |
418 |
||
2192 | 419 |
parameters := Array new:8. |
927 | 420 |
self endOfSequence |
421 |
||
422 |
"Created: / 10.6.1998 / 14:46:07 / cg" |
|
953 | 423 |
"Modified: / 13.6.1998 / 13:58:01 / cg" |
927 | 424 |
! |
425 |
||
426 |
initializeKeyboardSequences |
|
1420 | 427 |
"setup my keyboard sequences for a vt100" |
428 |
||
927 | 429 |
kbdSequences := (self vt100KeyCodes) |
430 |
||
431 |
"Modified: / 9.6.1998 / 20:49:21 / cg" |
|
432 |
"Created: / 10.6.1998 / 15:12:32 / cg" |
|
433 |
! ! |
|
434 |
||
4221 | 435 |
!VT100TerminalView methodsFor:'os functions (xterm)'! |
436 |
||
437 |
osCommand |
|
438 |
|cmdKey cmdValue| |
|
439 |
||
440 |
cmdKey := parameters at:1. |
|
441 |
cmdValue := parameters at:2. |
|
442 |
cmdKey == 0 ifTrue:[ |
|
443 |
"/ change icon name and window title |
|
444 |
masterWindow notNil ifTrue:[ |
|
445 |
masterWindow label:cmdValue. |
|
446 |
masterWindow iconLabel:cmdValue. |
|
447 |
]. |
|
448 |
self endOfSequence. |
|
449 |
^ self. |
|
450 |
]. |
|
451 |
cmdKey == 1 ifTrue:[ |
|
452 |
"/ change icon name |
|
453 |
masterWindow notNil ifTrue:[ |
|
454 |
masterWindow iconLabel:cmdValue. |
|
455 |
]. |
|
456 |
self endOfSequence. |
|
457 |
^ self. |
|
458 |
]. |
|
459 |
cmdKey == 2 ifTrue:[ |
|
460 |
"/ change window title |
|
461 |
masterWindow notNil ifTrue:[ |
|
462 |
masterWindow label:cmdValue. |
|
463 |
]. |
|
464 |
self endOfSequence. |
|
465 |
^ self. |
|
466 |
]. |
|
467 |
cmdKey == 3 ifTrue:[ |
|
468 |
"/ set x property |
|
469 |
self endOfSequence. |
|
470 |
^ self. |
|
471 |
]. |
|
472 |
cmdKey == 4 ifTrue:[ |
|
473 |
"/ change color |
|
474 |
self endOfSequence. |
|
475 |
^ self. |
|
476 |
]. |
|
477 |
self breakPoint:#cg. |
|
478 |
self endOfSequence |
|
479 |
! ! |
|
480 |
||
2498 | 481 |
!VT100TerminalView methodsFor:'processing-input'! |
927 | 482 |
|
2194 | 483 |
addToParameter:char |
927 | 484 |
"The parameter char is a digit. Add it to the current parameter." |
485 |
||
486 |
| param | |
|
487 |
||
2192 | 488 |
param := (parameters at:currentParam) ? 0. |
927 | 489 |
parameters at:currentParam put:(param * 10 + char digitValue) |
490 |
||
491 |
"Created: / 10.6.1998 / 14:39:00 / cg" |
|
492 |
! |
|
493 |
||
1420 | 494 |
endOfSequence |
495 |
"private - reset state-machine at end of escape-sequence" |
|
927 | 496 |
|
497 |
state := 0. |
|
498 |
currentParam := 1. |
|
2192 | 499 |
"/ parameters := Array new:8 withAll:0. |
500 |
parameters atAllPut:nil. |
|
927 | 501 |
|
502 |
"Created: / 10.6.1998 / 14:30:40 / cg" |
|
503 |
"Modified: / 10.6.1998 / 14:30:57 / cg" |
|
504 |
! |
|
505 |
||
2207 | 506 |
evaluateProcessCharacterReturn:aSymbol |
507 |
" evaluate the return value of the process state methods except for state 0 |
|
508 |
" |
|
509 |
||
510 |
aSymbol == #waitForNextChar ifTrue:[ |
|
511 |
^ self. |
|
512 |
]. |
|
513 |
aSymbol == #unknown ifTrue:[ |
|
514 |
self doNothing. |
|
515 |
^ self |
|
516 |
]. |
|
517 |
aSymbol == #sequenceComplete ifTrue:[ |
|
518 |
self endOfSequence. |
|
519 |
^ self. |
|
520 |
]. |
|
521 |
! |
|
522 |
||
523 |
nextPut:char |
|
2194 | 524 |
" process a character (i.e. the shells output) |
525 |
" |
|
937 | 526 |
|
2202 | 527 |
|processCharacterReturn| |
932 | 528 |
|
2192 | 529 |
Debug ifTrue:[ |
2202 | 530 |
Transcript |
531 |
show:state; |
|
532 |
show:' '; |
|
533 |
showCR:char storeString |
|
2192 | 534 |
]. |
2207 | 535 |
state == #gotReturn ifTrue:[ |
536 |
processCharacterReturn := self processStateGotReturn:char. |
|
537 |
processCharacterReturn == #sequenceComplete ifTrue:[ |
|
2350
0f9ca9ecf77a
the state have to be reset if sequence is complete in #gotReturn
penk
parents:
2268
diff
changeset
|
538 |
self endOfSequence. |
2207 | 539 |
^ self. |
540 |
]. |
|
541 |
]. |
|
927 | 542 |
state == 0 ifTrue:[ |
2207 | 543 |
processCharacterReturn := self processState0:char. |
544 |
processCharacterReturn == #waitForNextChar ifTrue:[ |
|
545 |
^ self. |
|
546 |
]. |
|
547 |
processCharacterReturn == #unknown ifTrue:[ |
|
548 |
super nextPut:char. |
|
549 |
^ self. |
|
550 |
]. |
|
551 |
]. |
|
552 |
state == #gotESC ifTrue:[ |
|
553 |
processCharacterReturn := self processStateGotESC:char. |
|
554 |
self evaluateProcessCharacterReturn:processCharacterReturn. |
|
555 |
^ self. |
|
927 | 556 |
]. |
2207 | 557 |
state == #gotCSI ifTrue:[ |
558 |
processCharacterReturn := self processStateGotCSI:char. |
|
559 |
self evaluateProcessCharacterReturn:processCharacterReturn. |
|
560 |
^ self. |
|
2202 | 561 |
]. |
2207 | 562 |
state == #gotCSI2 ifTrue:[ |
563 |
processCharacterReturn := self processStateGotCSI2:char. |
|
564 |
self evaluateProcessCharacterReturn:processCharacterReturn. |
|
565 |
^ self. |
|
2192 | 566 |
]. |
2207 | 567 |
state == #gotCSI3 ifTrue:[ |
568 |
processCharacterReturn := self processStateGotCSI3:char. |
|
569 |
self evaluateProcessCharacterReturn:processCharacterReturn. |
|
570 |
^ self. |
|
2192 | 571 |
]. |
2207 | 572 |
state == #gotXTERMCSI ifTrue:[ |
573 |
processCharacterReturn := self processStateGotXTERMCSI:char. |
|
574 |
self evaluateProcessCharacterReturn:processCharacterReturn. |
|
575 |
^ self. |
|
927 | 576 |
]. |
4221 | 577 |
state == #gotXTERMCSI2 ifTrue:[ |
578 |
processCharacterReturn := self processStateGotXTERMCSI2:char. |
|
579 |
self evaluateProcessCharacterReturn:processCharacterReturn. |
|
580 |
^ self. |
|
581 |
]. |
|
582 |
self halt:'unknown state'. |
|
2192 | 583 |
self doNothing. |
584 |
^ self |
|
2202 | 585 |
! |
586 |
||
2207 | 587 |
processState0:char |
2202 | 588 |
" change state or processing character; return |
589 |
#waitForNextChar - state was changed and wait for next characters |
|
590 |
#sequenceComplete - command processed |
|
591 |
#unknown - unknown character for this state |
|
592 |
" |
|
593 |
||
594 |
char asciiValue < 32 ifTrue:[ |
|
2207 | 595 |
(char == Character esc) ifTrue:[ |
596 |
state := #gotESC. |
|
597 |
^ #waitForNextChar |
|
598 |
]. |
|
2202 | 599 |
( char == Character nl "nl or '\n'" |
600 |
or:[(char == (Character value:16rb))]) ifTrue:[ |
|
2207 | 601 |
translateNLToCRNL == true ifTrue:[ |
602 |
self endEntry. |
|
603 |
self cursorToBeginOfLine. |
|
604 |
]. |
|
2202 | 605 |
self endEntry. |
606 |
self doCursorDown:1. |
|
2207 | 607 |
^ #waitForNextChar. |
2202 | 608 |
]. |
609 |
(char == Character return) ifTrue:[ |
|
610 |
(rangeEndLine notNil and:[rangeEndLine ~~ numberOfLines]) ifTrue:[ |
|
611 |
self endEntry. |
|
612 |
self cursorToBeginOfLine. |
|
613 |
] ifFalse:[ |
|
614 |
state := #gotReturn. |
|
615 |
]. |
|
2207 | 616 |
^ #waitForNextChar. |
2202 | 617 |
]. |
618 |
(char == Character backspace) ifTrue:[ |
|
619 |
self endEntry. |
|
620 |
self cursorLeft. |
|
2207 | 621 |
^ #waitForNextChar "/ doBackspace |
2202 | 622 |
]. |
623 |
(char == Character bell) ifTrue:[ |
|
2782 | 624 |
self shown ifTrue:[ |
625 |
self beep. |
|
626 |
]. |
|
2207 | 627 |
^ #waitForNextChar |
2202 | 628 |
]. |
629 |
(char == (Character value:5)) ifTrue:[ |
|
630 |
"/ Transmission answerback message |
|
631 |
self reportTerminalType. |
|
2207 | 632 |
^ #waitForNextChar |
2202 | 633 |
]. |
634 |
( char == (Character value:16r18) "/Cancel |
|
635 |
or:[ char == (Character value:16r1A) "/Substitute |
|
636 |
]) ifTrue:[ |
|
637 |
self nextPut:(Character value:16r2). |
|
2207 | 638 |
^ #waitForNextChar |
2202 | 639 |
] |
2207 | 640 |
" |
641 |
all not suported control characters (also vt102): |
|
642 |
Character value:16r3 ->End of text |
|
643 |
Character value:16r4 ->End of transmission |
|
644 |
Character tab ->Horizontal tab |
|
645 |
Character value:16rc ->Form feed |
|
646 |
Character value:16re ->SO shift out |
|
647 |
Character value:16rf ->SI shift in |
|
648 |
Character value:16r11 ->Device control 1 |
|
649 |
Character value:16r13 ->Device control 3 |
|
650 |
". |
|
651 |
char ~~ Character tab ifTrue:[ |
|
652 |
char asciiValue ~~ 0 ifTrue:[ |
|
653 |
('VT100 [info]: unhandled control key: ' , char storeString) infoPrintCR. |
|
654 |
]. |
|
655 |
^ #waitForNextChar. |
|
656 |
] |
|
657 |
||
2202 | 658 |
]. |
659 |
^ #unknown |
|
2192 | 660 |
! |
661 |
||
662 |
processStateGotCSI2:char |
|
663 |
" change state or processing character; return |
|
664 |
#waitForNextChar - state was changed and wait for next characters |
|
665 |
#sequenceComplete - command processed |
|
666 |
#unknown - unknown character for this state |
|
667 |
" |
|
668 |
||
669 |
char == $; ifTrue: [ |
|
670 |
currentParam := (currentParam + 1) min: 8. |
|
671 |
^ #waitForNextChar |
|
672 |
]. |
|
673 |
char isDigit ifTrue: [ |
|
2194 | 674 |
self addToParameter:char. |
2192 | 675 |
^ #waitForNextChar |
676 |
]. |
|
677 |
(char == $l |
|
678 |
or:[char == $h]) ifTrue: [ |
|
679 |
"/ (parameters at: 1) = 1 ifTrue: [app_cur_keys:(char == $h)]. |
|
680 |
"/ (parameters at: 1) = 2 ifTrue: [mode132:(char == $h)]. |
|
681 |
"/ (parameters at: 1) = 4 ifTrue: [smoothScroll:(char == $h)]. |
|
682 |
"/ (parameters at: 1) = 5 ifTrue: [reverseVideo:(char == $h)]. |
|
683 |
"/ (parameters at: 1) = 6 ifTrue: [decom:(char == $h)]. |
|
684 |
self endEntry. |
|
685 |
(parameters at: 1) = 7 ifTrue: [self autoMargin:(char == $h)]. |
|
686 |
^ #sequenceComplete |
|
687 |
]. |
|
688 |
^ #unknown |
|
689 |
! |
|
690 |
||
691 |
processStateGotCSI3:char |
|
692 |
" change state or processing character; return |
|
693 |
#waitForNextChar - state was changed and wait for next characters |
|
694 |
#sequenceComplete - command processed |
|
695 |
#unknown - unknown character for this state |
|
696 |
" |
|
697 |
||
698 |
^ #unknown |
|
699 |
! |
|
700 |
||
701 |
processStateGotCSI:char |
|
702 |
" change state or processing character; return |
|
703 |
#waitForNextChar - state was changed and wait for next characters |
|
704 |
#sequenceComplete - command processed |
|
705 |
#unknown - unknown character for this state |
|
706 |
" |
|
707 |
||
708 |
char == $? ifTrue: [ |
|
709 |
state := #gotCSI2. |
|
710 |
^ #waitForNextChar |
|
711 |
]. |
|
712 |
char == $; ifTrue:[ |
|
713 |
currentParam := (currentParam + 1) min: 8. |
|
714 |
^ #waitForNextChar |
|
715 |
]. |
|
716 |
char isDigit ifTrue: [ |
|
717 |
self addToParameter:char. |
|
718 |
^ #waitForNextChar |
|
719 |
]. |
|
720 |
char == $@ ifTrue: [ |
|
721 |
self endEntry. |
|
722 |
self insertCharacters. |
|
723 |
^ #sequenceComplete |
|
724 |
]. |
|
725 |
char == $A ifTrue: [ |
|
726 |
"/ ESC[#A - Moves cursor up # lines |
|
727 |
self endEntry. |
|
2202 | 728 |
self doCursorUp:(self getParameter:1 withDefault:1). |
2192 | 729 |
^ #sequenceComplete |
730 |
]. |
|
731 |
char == $B ifTrue: [ |
|
732 |
"/ ESC[#B - Moves cursor down # lines |
|
733 |
self endEntry. |
|
2202 | 734 |
self doCursorDown:(self getParameter:1 withDefault:1). |
2192 | 735 |
^ #sequenceComplete |
736 |
]. |
|
737 |
char == $C ifTrue: [ |
|
738 |
"/ ESC[#C - Moves cursor forward # spaces |
|
739 |
self endEntry. |
|
2202 | 740 |
self doCursorRight:(self getParameter:1 withDefault:1). |
2192 | 741 |
^ #sequenceComplete |
742 |
]. |
|
743 |
char == $D ifTrue: [ |
|
744 |
"/ ESC[#D - Moves cursor back # spaces |
|
745 |
self endEntry. |
|
2202 | 746 |
self doCursorLeft:(self getParameter:1 withDefault:1). |
2192 | 747 |
^ #sequenceComplete |
748 |
]. |
|
2202 | 749 |
(char == $H or:[char == $f]) ifTrue: [ |
2192 | 750 |
"/ ESC[#;#H or ESC[#;#f - Moves cusor to line #, column # |
751 |
self endEntry. |
|
2202 | 752 |
self move. |
2192 | 753 |
^ #sequenceComplete |
754 |
]. |
|
755 |
char == $J ifTrue: [ |
|
2217 | 756 |
"/ ESC[0J - Clear screen to end |
757 |
"/ ESC[1J - Clear screen from beginning |
|
2192 | 758 |
"/ ESC[2J - Clear entire screen and home cursor |
759 |
self endEntry. |
|
2207 | 760 |
self doClearDisplay:(self getParameter:1 withDefault:0). |
2192 | 761 |
^ #sequenceComplete |
762 |
]. |
|
763 |
char == $K ifTrue: [ |
|
764 |
"/ ESC[K - Clear to end of line |
|
765 |
self endEntry. |
|
2207 | 766 |
self clearLines:(self getParameter:1 withDefault:0). |
2192 | 767 |
Debug ifTrue:[ |
768 |
Transcript showCR:'clear to EOL'. |
|
769 |
]. |
|
770 |
^ #sequenceComplete |
|
771 |
]. |
|
772 |
char == $L ifTrue: [ |
|
773 |
self endEntry. |
|
774 |
self insertLines. |
|
775 |
^ #sequenceComplete |
|
776 |
]. |
|
777 |
char == $M ifTrue: [ |
|
778 |
self endEntry. |
|
779 |
self deleteLines. |
|
780 |
^ #sequenceComplete |
|
781 |
]. |
|
782 |
char == $P ifTrue: [ |
|
783 |
self endEntry. |
|
784 |
self deleteCharacters. |
|
785 |
^ #sequenceComplete |
|
786 |
]. |
|
2202 | 787 |
char == $R ifTrue: [ |
2192 | 788 |
"/ ESC[#;#R - Reports current cursor line & column |
2207 | 789 |
^ #unknown |
2192 | 790 |
]. |
791 |
(char == $c) ifTrue:[ |
|
792 |
"/ terminal-type query 3 |
|
793 |
self reportTerminalType. |
|
794 |
^ #sequenceComplete |
|
795 |
]. |
|
796 |
char == $n ifTrue: [ |
|
797 |
self report. |
|
798 |
^ #sequenceComplete |
|
799 |
]. |
|
800 |
char == $m ifTrue: [ |
|
2207 | 801 |
self displayMode:(self getParameter:1 withDefault:0). |
2192 | 802 |
^ #sequenceComplete |
803 |
]. |
|
804 |
char == $r ifTrue: [ |
|
805 |
self endEntry. |
|
806 |
self resetDefaults. |
|
807 |
^ #sequenceComplete |
|
808 |
]. |
|
809 |
char == $s ifTrue: [ |
|
810 |
"/ ESC[s - Saves cursor position for recall later |
|
811 |
self endEntry. |
|
812 |
^ #sequenceComplete |
|
813 |
]. |
|
814 |
char == $u ifTrue: [ |
|
815 |
"/ ESC[u - Return to saved cursor position |
|
816 |
self endEntry. |
|
817 |
^ #sequenceComplete |
|
818 |
]. |
|
819 |
^ #unknown |
|
820 |
! |
|
821 |
||
822 |
processStateGotESC:char |
|
823 |
" change state or processing character; return |
|
824 |
#waitForNextChar - state was changed and wait for next characters |
|
825 |
#sequenceComplete - command processed |
|
826 |
#unknown - unknown character for this state |
|
827 |
" |
|
828 |
||
829 |
char == $[ ifTrue: [ |
|
830 |
"/ ESC-[ |
|
831 |
state := #gotCSI. |
|
832 |
^ #waitForNextChar |
|
833 |
]. |
|
834 |
char == $] ifTrue: [ |
|
835 |
"/ ESC-] |
|
836 |
"/xterm sequence |
|
837 |
state := #gotXTERMCSI. |
|
838 |
^ #waitForNextChar |
|
839 |
]. |
|
840 |
char == $( ifTrue: [ |
|
841 |
"/ ESC-( |
|
842 |
"/ todo: set-charset 0 ... |
|
843 |
state := #gotCSI3. |
|
844 |
^ #waitForNextChar |
|
845 |
]. |
|
846 |
char == $) ifTrue: [ |
|
847 |
"/ ESC-( |
|
848 |
"/ todo: set-charset 1 ... |
|
2207 | 849 |
^ #unknown |
2192 | 850 |
]. |
851 |
char == $7 ifTrue:[ |
|
852 |
"/ ESC-7 |
|
853 |
self endEntry. |
|
854 |
self saveCursor. |
|
855 |
^ #sequenceComplete |
|
856 |
]. |
|
857 |
char == $8 ifTrue:[ |
|
858 |
"/ ESC-7 |
|
859 |
self endEntry. |
|
860 |
self restoreCursor. |
|
861 |
^ #sequenceComplete |
|
862 |
]. |
|
863 |
char == $M ifTrue:[ |
|
2217 | 864 |
"/ ESC-M cursor up |
2192 | 865 |
self endEntry. |
866 |
self doCursorUp:1. |
|
867 |
^ #sequenceComplete |
|
868 |
]. |
|
869 |
char == $D ifTrue:[ |
|
2217 | 870 |
"/ ESC-D Index cursor down one line in same column |
2192 | 871 |
self endEntry. |
872 |
self doCursorDown:1. |
|
873 |
^ #sequenceComplete |
|
874 |
]. |
|
875 |
char == $E ifTrue:[ |
|
876 |
"/ ESC-E |
|
877 |
"/ TODO add_lines |
|
2217 | 878 |
self endEntry. |
879 |
self cursorReturn. |
|
2192 | 880 |
^ #sequenceComplete |
881 |
]. |
|
882 |
(char == $Z) ifTrue:[ |
|
883 |
"/ terminal-type query 2 |
|
884 |
self reportTerminalType. |
|
885 |
^ #sequenceComplete |
|
886 |
]. |
|
887 |
char == $= ifTrue: [ |
|
888 |
"/ enter apllication keypad mode |
|
889 |
"/ ESC-= |
|
2207 | 890 |
^ #unknown |
2192 | 891 |
]. |
892 |
char == $> ifTrue: [ |
|
893 |
"/ exit apllication keypad mode |
|
894 |
"/ ESC-< |
|
2207 | 895 |
^ #unknown |
2192 | 896 |
]. |
897 |
^ #unknown |
|
898 |
! |
|
899 |
||
2202 | 900 |
processStateGotReturn:char |
901 |
" change state or processing character; return |
|
902 |
#waitForNextChar - state was changed and wait for next characters |
|
903 |
#sequenceComplete - command processed |
|
904 |
#unknown - unknown character for this state |
|
905 |
" |
|
906 |
||
2207 | 907 |
state := 0. |
2202 | 908 |
char == Character nl ifTrue:[ |
909 |
"/ cr-nl |
|
910 |
"/ stay in buffering mode. |
|
2207 | 911 |
super nextPut:Character cr. |
912 |
^ #sequenceComplete. |
|
2202 | 913 |
]. |
914 |
self endEntry. |
|
915 |
self cursorToBeginOfLine. |
|
916 |
"/ continue in initial state |
|
2207 | 917 |
^ #waitForNextChar |
2202 | 918 |
! |
919 |
||
4221 | 920 |
processStateGotXTERMCSI2:char |
921 |
" change state or processing character; return |
|
922 |
#waitForNextChar - state was changed and wait for next characters |
|
923 |
#sequenceComplete - command processed |
|
924 |
#unknown - unknown character for this state |
|
925 |
" |
|
926 |
||
927 |
char == (Character value:7) ifTrue: [ |
|
928 |
parameters at:currentParam put:(parameters at:currentParam) contents. |
|
929 |
self osCommand. |
|
930 |
^ #sequenceComplete |
|
931 |
]. |
|
932 |
"/ add to parameter |
|
933 |
(parameters at:currentParam) nextPut:char. |
|
934 |
^ #waitForNextChar |
|
935 |
! |
|
936 |
||
2192 | 937 |
processStateGotXTERMCSI:char |
938 |
" change state or processing character; return |
|
939 |
#waitForNextChar - state was changed and wait for next characters |
|
940 |
#sequenceComplete - command processed |
|
941 |
#unknown - unknown character for this state |
|
942 |
" |
|
943 |
||
4221 | 944 |
char == $; ifTrue:[ |
945 |
currentParam := (currentParam + 1) min: 8. |
|
946 |
parameters at:currentParam put:(WriteStream on:''). |
|
947 |
state := #gotXTERMCSI2. |
|
948 |
^ #waitForNextChar |
|
949 |
]. |
|
950 |
char isDigit ifTrue: [ |
|
951 |
self addToParameter:char. |
|
952 |
^ #waitForNextChar |
|
953 |
]. |
|
2192 | 954 |
^ #unknown |
920 | 955 |
! ! |
956 |
||
930 | 957 |
!VT100TerminalView methodsFor:'queries'! |
958 |
||
2202 | 959 |
getParameter:para withDefault:default |
960 |
||
961 |
|parameter| |
|
962 |
||
963 |
parameter := (parameters at:para). |
|
964 |
^ ((parameter isNil or:[parameter = 0]) ifTrue:[default] ifFalse:[parameter]). |
|
965 |
! |
|
966 |
||
930 | 967 |
terminalType |
1420 | 968 |
"returns a string describing this terminal (usually, this is |
969 |
passed down to the shell as TERM environment variable). |
|
970 |
Here, 'vt100' is returned." |
|
971 |
||
1355 | 972 |
^ 'vt100' |
930 | 973 |
|
974 |
"Created: / 10.6.1998 / 16:22:39 / cg" |
|
1355 | 975 |
"Modified: / 5.5.1999 / 11:22:40 / cg" |
930 | 976 |
! ! |
977 |
||
920 | 978 |
!VT100TerminalView class methodsFor:'documentation'! |
979 |
||
980 |
version |
|
4221 | 981 |
^ '$Header: /cvs/stx/stx/libwidg2/VT100TerminalView.st,v 1.45 2013-05-24 14:36:24 cg Exp $' |
920 | 982 |
! ! |
4221 | 983 |