author | Claus Gittinger <cg@exept.de> |
Sat, 20 Jun 1998 17:37:02 +0200 | |
changeset 976 | 40af522dda86 |
parent 956 | 606dee2ae341 |
child 978 | 8f6dee49a562 |
permissions | -rw-r--r-- |
930 | 1 |
TerminalView subclass:#VT100TerminalView |
951 | 2 |
instanceVariableNames:'state currentParam parameters lastCursorLine' |
920 | 3 |
classVariableNames:'' |
4 |
poolDictionaries:'' |
|
5 |
category:'Views-TerminalViews' |
|
6 |
! |
|
7 |
||
927 | 8 |
!VT100TerminalView class methodsFor:'documentation'! |
9 |
||
10 |
documentation |
|
11 |
" |
|
12 |
VT100 terminal |
|
13 |
||
14 |
[start with:] |
|
15 |
VT100TerminalView openShell |
|
16 |
" |
|
17 |
||
18 |
||
19 |
! ! |
|
920 | 20 |
|
932 | 21 |
!VT100TerminalView methodsFor:'defaults'! |
927 | 22 |
|
23 |
vt100KeyCodes |
|
24 |
^ IdentityDictionary withKeysAndValues: |
|
25 |
#( |
|
26 |
#CursorUp '\e[A' |
|
27 |
#CursorDown '\e[B' |
|
28 |
#CursorRight '\e[C' |
|
29 |
#CursorLeft '\e[D' |
|
30 |
#Home '\e[H' |
|
31 |
#Escape '\e' |
|
32 |
#BackSpace '\b' |
|
33 |
#Return '\r' |
|
976 | 34 |
#Delete '\0177' |
927 | 35 |
) |
36 |
||
37 |
"Created: / 10.6.1998 / 15:13:01 / cg" |
|
976 | 38 |
"Modified: / 20.6.1998 / 17:36:33 / cg" |
927 | 39 |
! ! |
40 |
||
41 |
!VT100TerminalView methodsFor:'functions'! |
|
42 |
||
43 |
addLines |
|
44 |
"Add the appropriate number of blank lines at the position |
|
45 |
indicated by the cursor." |
|
46 |
||
47 |
self addLines: ((parameters at: 1) max: 1). |
|
48 |
self endOfSequence |
|
49 |
||
50 |
"Created: / 10.6.1998 / 14:48:03 / cg" |
|
51 |
! |
|
52 |
||
53 |
addLines: aNumber |
|
54 |
"Add aNumber blank lines at the position indicated by the cursor." |
|
55 |
||
56 |
aNumber timesRepeat: [ |
|
57 |
self insertLine:'' before:cursorLine |
|
58 |
] |
|
59 |
||
60 |
"Created: / 10.6.1998 / 14:49:30 / cg" |
|
61 |
! |
|
62 |
||
949 | 63 |
autoMargin:aBoolean |
64 |
"set/clear autowrap at end of line (not yet implemented)" |
|
65 |
||
66 |
"Created: / 12.6.1998 / 21:42:06 / cg" |
|
67 |
! |
|
68 |
||
927 | 69 |
clearLines |
70 |
"Clear some part of the current line, as indicated by the first parameter." |
|
71 |
||
72 |
(parameters at: 1) = 0 ifTrue: [^self doClearToEndOfLine]. |
|
73 |
(parameters at: 1) = 1 ifTrue: [^self doClearFromBeginningOfLine]. |
|
74 |
(parameters at: 1) = 2 ifTrue: [^self doClearEntireLine] |
|
75 |
||
76 |
"Created: / 10.6.1998 / 14:44:22 / cg" |
|
77 |
! |
|
78 |
||
949 | 79 |
deleteCharacters |
80 |
"Delete the appropriate number of characters at the position |
|
81 |
indicated by the cursor." |
|
82 |
||
83 |
|n| |
|
84 |
||
85 |
n := ((parameters at: 1) max: 1). |
|
86 |
self deleteFromLine:cursorLine col:cursorCol toLine:cursorLine col:cursorCol+n-1. |
|
87 |
||
88 |
"Created: / 12.6.1998 / 21:19:02 / cg" |
|
89 |
"Modified: / 12.6.1998 / 21:19:15 / cg" |
|
90 |
! |
|
91 |
||
927 | 92 |
displayMode: anInteger |
93 |
"Set the current display mode." |
|
94 |
||
951 | 95 |
(parameters at:1) == 1 ifTrue:[ |
96 |
"/ ESC-[-1-m -> bold |
|
97 |
||
98 |
currentEmphasis := #bold. |
|
99 |
^ self. |
|
100 |
]. |
|
101 |
currentEmphasis := nil. |
|
102 |
||
927 | 103 |
"/ displayMode _ anInteger!! |
104 |
||
105 |
"Created: / 10.6.1998 / 15:01:16 / cg" |
|
951 | 106 |
"Modified: / 12.6.1998 / 22:26:30 / cg" |
927 | 107 |
! |
108 |
||
949 | 109 |
insertCaharcters |
110 |
"Insert the appropriate number of spaces at the position |
|
111 |
indicated by the cursor." |
|
112 |
||
113 |
|s| |
|
114 |
||
115 |
s := String new:((parameters at: 1) max: 1). |
|
116 |
self insertStringWithoutCRsAtLine:cursorLine col:cursorCol. |
|
117 |
||
118 |
"Created: / 10.6.1998 / 14:48:03 / cg" |
|
119 |
"Modified: / 12.6.1998 / 21:14:25 / cg" |
|
120 |
! |
|
121 |
||
927 | 122 |
move |
123 |
"Move to the locations indicated by the first and second parameters." |
|
124 |
||
125 |
self moveToX: ((parameters at: 2) max: 1) y: ((parameters at: 1) max: 1). |
|
126 |
self endOfSequence |
|
127 |
||
128 |
"Created: / 10.6.1998 / 14:40:01 / cg" |
|
129 |
! |
|
130 |
||
131 |
moveToX: xLocation y: yLocation |
|
132 |
"Position the cursor at the location given by xLocation and yLocation. |
|
133 |
Ignore the command if the parameters are outside the allowable range." |
|
134 |
||
135 |
(xLocation < 1 or: [xLocation > numberOfColumns]) ifTrue: [^self]. |
|
136 |
(yLocation < 1 or: [yLocation > numberOfLines]) ifTrue: [^self]. |
|
952 | 137 |
|
949 | 138 |
self cursorVisibleLine:yLocation col:xLocation. |
927 | 139 |
|
140 |
"Created: / 10.6.1998 / 14:40:49 / cg" |
|
952 | 141 |
"Modified: / 12.6.1998 / 23:04:40 / cg" |
927 | 142 |
! |
143 |
||
944 | 144 |
reportTerminalType |
145 |
(parameters at: 1) == 6 ifTrue:[ |
|
146 |
"/ report position |
|
147 |
inStream nextPut:(Character esc). |
|
148 |
inStream nextPutAll:'[' |
|
149 |
, cursorLine printString |
|
150 |
, ';' |
|
151 |
, cursorCol printString |
|
152 |
, 'R'. |
|
153 |
^ self |
|
154 |
]. |
|
155 |
(parameters at: 1) == 7 ifTrue:[ |
|
156 |
"/ display name |
|
157 |
]. |
|
158 |
||
159 |
"Created: / 11.6.1998 / 23:05:50 / cg" |
|
160 |
"Modified: / 11.6.1998 / 23:09:10 / cg" |
|
161 |
! |
|
162 |
||
927 | 163 |
resetDefaults |
164 |
"Reset the default parameters" |
|
165 |
||
949 | 166 |
|l1 c1 l2 c2| |
167 |
||
168 |
l1 := (parameters at: 1). |
|
169 |
l2 := (parameters at: 2). |
|
170 |
(l1 ~~ 0 and:[l2 ~~ 0]) ifTrue:[ |
|
171 |
rangeStartLine := l1. |
|
172 |
rangeEndLine := l2. |
|
173 |
] ifFalse:[ |
|
174 |
self halt. |
|
175 |
]. |
|
176 |
||
927 | 177 |
"/ autoLineFeed _ false. |
178 |
"/ autoMargin _ true. |
|
179 |
"/ displayMode _ 0. "Normal display"!! !! |
|
180 |
||
181 |
"Created: / 10.6.1998 / 14:50:53 / cg" |
|
949 | 182 |
"Modified: / 12.6.1998 / 21:24:48 / cg" |
920 | 183 |
! ! |
184 |
||
185 |
!VT100TerminalView methodsFor:'initialization'! |
|
186 |
||
927 | 187 |
initialize |
188 |
super initialize. |
|
949 | 189 |
|
927 | 190 |
self endOfSequence |
191 |
||
192 |
"Created: / 10.6.1998 / 14:46:07 / cg" |
|
953 | 193 |
"Modified: / 13.6.1998 / 13:58:01 / cg" |
927 | 194 |
! |
195 |
||
196 |
initializeKeyboardSequences |
|
197 |
kbdSequences := (self vt100KeyCodes) |
|
198 |
||
199 |
"Modified: / 9.6.1998 / 20:49:21 / cg" |
|
200 |
"Created: / 10.6.1998 / 15:12:32 / cg" |
|
201 |
! ! |
|
202 |
||
203 |
!VT100TerminalView methodsFor:'processing - input'! |
|
204 |
||
205 |
addToParameter: char |
|
206 |
"The parameter char is a digit. Add it to the current parameter." |
|
207 |
||
208 |
| param | |
|
209 |
||
210 |
param := parameters at:currentParam. |
|
211 |
parameters at:currentParam put:(param * 10 + char digitValue) |
|
212 |
||
213 |
"Created: / 10.6.1998 / 14:39:00 / cg" |
|
214 |
! |
|
215 |
||
216 |
doNothing |
|
217 |
self endOfSequence |
|
218 |
||
219 |
"Created: / 10.6.1998 / 14:31:56 / cg" |
|
220 |
! |
|
221 |
||
222 |
endOfSequence |
|
223 |
state := 0. |
|
224 |
currentParam := 1. |
|
225 |
parameters := Array new:8 withAll:0. |
|
226 |
||
227 |
"Created: / 10.6.1998 / 14:30:40 / cg" |
|
228 |
"Modified: / 10.6.1998 / 14:30:57 / cg" |
|
229 |
! |
|
230 |
||
231 |
nextPut:char |
|
937 | 232 |
"process a character (i.e. the shells output)" |
233 |
||
944 | 234 |
"/ Transcript show:state; show:' '; showCR:char storeString. |
932 | 235 |
|
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
236 |
state == #gotReturn ifTrue:[ |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
237 |
state := 0. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
238 |
char == Character nl ifTrue:[ |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
239 |
"/ cr-nl |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
240 |
"/ stay in buffering mode. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
241 |
super nextPut:Character cr. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
242 |
^ self. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
243 |
]. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
244 |
self endEntry. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
245 |
self cursorToBeginOfLine. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
246 |
"/ continue in initial state |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
247 |
]. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
248 |
|
927 | 249 |
state == 0 ifTrue:[ |
250 |
"/ Currently, we are in initial state. |
|
251 |
"/ Decide what to do on the basis of the parameter char. |
|
252 |
||
253 |
(char == Character esc) ifTrue:[ |
|
254 |
self endEntry. |
|
944 | 255 |
state := #gotESC. ^ self |
927 | 256 |
]. |
257 |
(char == Character nl) ifTrue:[ |
|
956 | 258 |
self doCursorDown:1. |
259 |
^ self endEntry. |
|
932 | 260 |
]. |
261 |
(char == Character return) ifTrue:[ |
|
951 | 262 |
rangeEndLine ~~ numberOfLines ifTrue:[ |
263 |
self endEntry. |
|
264 |
self cursorToBeginOfLine. |
|
265 |
] ifFalse:[ |
|
266 |
state := #gotReturn. |
|
267 |
]. |
|
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
268 |
^ self. |
927 | 269 |
]. |
270 |
(char == Character backspace) ifTrue:[ |
|
271 |
self endEntry. |
|
941 | 272 |
^ self cursorLeft. "/ doBackspace |
927 | 273 |
]. |
932 | 274 |
(char == Character bell) ifTrue:[ |
275 |
self beep. |
|
276 |
^ self |
|
277 |
]. |
|
944 | 278 |
(char == (Character value:5)) ifTrue:[ |
279 |
"/ terminal-type query |
|
280 |
self reportTerminalType. |
|
281 |
^ self |
|
282 |
]. |
|
934 | 283 |
^ super nextPut:char |
927 | 284 |
]. |
285 |
||
944 | 286 |
state == #gotESC ifTrue:[ |
927 | 287 |
"/ Currently, we are in ESC state. |
288 |
"/ Decide what to do on the basis of the parameter char. |
|
289 |
||
290 |
char == $[ ifTrue: [ |
|
291 |
"/ ESC-[ |
|
944 | 292 |
state := #gotCSI. |
293 |
^ self |
|
294 |
]. |
|
295 |
char == $] ifTrue: [ |
|
296 |
"/ ESC-] |
|
297 |
"/xterm sequence |
|
298 |
state := #gotXTERMCSI. |
|
927 | 299 |
^ self |
300 |
]. |
|
944 | 301 |
char == $( ifTrue: [ |
302 |
"/ ESC-( |
|
303 |
"/ todo: set-charset 0 ... |
|
304 |
^ self doNothing |
|
305 |
]. |
|
306 |
char == $) ifTrue: [ |
|
307 |
"/ ESC-( |
|
308 |
"/ todo: set-charset 1 ... |
|
309 |
^ self doNothing |
|
310 |
]. |
|
311 |
char == $7 ifTrue:[ |
|
312 |
"/ ESC-7 |
|
313 |
self saveCursor. |
|
314 |
^ self endOfSequence |
|
315 |
]. |
|
316 |
char == $8 ifTrue:[ |
|
317 |
"/ ESC-7 |
|
318 |
self restoreCursor. |
|
319 |
^ self endOfSequence |
|
320 |
]. |
|
927 | 321 |
char == $M ifTrue:[ |
322 |
"/ ESC-M |
|
951 | 323 |
self doCursorUp:1. |
927 | 324 |
^ self endOfSequence |
325 |
]. |
|
326 |
char == $D ifTrue:[ |
|
327 |
"/ ESC-D |
|
951 | 328 |
self doCursorDown:1. |
927 | 329 |
^ self endOfSequence |
330 |
]. |
|
944 | 331 |
char == $E ifTrue:[ |
332 |
"/ ESC-E |
|
333 |
"/ TODO add_lines |
|
334 |
^ self doNothing |
|
335 |
]. |
|
336 |
(char == $Z) ifTrue:[ |
|
337 |
"/ terminal-type query 2 |
|
338 |
self reportTerminalType. |
|
339 |
^ self endOfSequence |
|
340 |
]. |
|
927 | 341 |
^ self doNothing |
342 |
]. |
|
343 |
||
944 | 344 |
state == #gotCSI ifTrue:[ |
927 | 345 |
"/ Currently, we are in ESC-[ state. |
346 |
"/ Decide what to do on the basis of the parameter char. |
|
347 |
||
348 |
char == $; ifTrue:[ |
|
349 |
currentParam := (currentParam + 1) min: 8. |
|
350 |
^ self |
|
351 |
]. |
|
352 |
char isDigit ifTrue: [ |
|
353 |
^ self addToParameter:char |
|
354 |
]. |
|
355 |
char == $@ ifTrue: [ |
|
951 | 356 |
self insertCharacters. |
357 |
^ self endOfSequence |
|
927 | 358 |
]. |
359 |
char == $A ifTrue: [ |
|
951 | 360 |
self doCursorUp:((parameters at: 1) max: 1). |
927 | 361 |
^ self endOfSequence |
362 |
]. |
|
363 |
char == $B ifTrue: [ |
|
364 |
self doCursorLeft:((parameters at: 1) max: 1). |
|
365 |
^ self endOfSequence |
|
366 |
]. |
|
367 |
char == $C ifTrue: [ |
|
368 |
self doCursorRight:((parameters at: 1) max: 1). |
|
369 |
^ self endOfSequence |
|
370 |
]. |
|
371 |
char == $D ifTrue: [ |
|
951 | 372 |
self doCursorDown:((parameters at: 1) max: 1). |
927 | 373 |
^ self endOfSequence |
374 |
]. |
|
375 |
char == $H ifTrue: [ |
|
376 |
self move. |
|
377 |
^ self endOfSequence |
|
378 |
]. |
|
379 |
char == $J ifTrue: [ |
|
380 |
self doClearDisplay. |
|
381 |
^ self endOfSequence |
|
382 |
]. |
|
383 |
char == $K ifTrue: [ |
|
384 |
self clearLines. |
|
385 |
^ self endOfSequence |
|
386 |
]. |
|
387 |
char == $L ifTrue: [ |
|
944 | 388 |
self insertLines. |
927 | 389 |
^ self endOfSequence |
390 |
]. |
|
391 |
char == $M ifTrue: [ |
|
392 |
self deleteLines. |
|
393 |
^ self endOfSequence |
|
394 |
]. |
|
395 |
char == $P ifTrue: [ |
|
396 |
self deleteCharacters. |
|
397 |
^ self endOfSequence |
|
398 |
]. |
|
944 | 399 |
(char == $c) ifTrue:[ |
400 |
"/ terminal-type query 3 |
|
401 |
self reportTerminalType. |
|
402 |
^ self endOfSequence |
|
403 |
]. |
|
404 |
char == $f ifTrue: [ |
|
405 |
self move. |
|
406 |
^ self endOfSequence |
|
407 |
]. |
|
408 |
char == $n ifTrue: [ |
|
409 |
self report. |
|
410 |
^ self endOfSequence |
|
411 |
]. |
|
927 | 412 |
char == $m ifTrue: [ |
413 |
self displayMode: (parameters at: 1). |
|
414 |
^ self endOfSequence |
|
415 |
]. |
|
416 |
char == $r ifTrue: [ |
|
417 |
self resetDefaults. |
|
418 |
^ self endOfSequence |
|
419 |
]. |
|
420 |
char == $? ifTrue: [ |
|
944 | 421 |
state := #gotCSI2. |
927 | 422 |
^ self |
423 |
]. |
|
939 | 424 |
^ self doNothing |
927 | 425 |
]. |
426 |
||
944 | 427 |
state == #gotCSI2 ifTrue:[ |
927 | 428 |
"/ Currently, we are in ESC-[-? state. |
429 |
"/ Decide what to do on the basis of the parameter char. |
|
430 |
||
431 |
char == $; ifTrue: [ |
|
432 |
currentParam := (currentParam + 1) min: 8. |
|
433 |
^ self |
|
434 |
]. |
|
435 |
char isDigit ifTrue: [ |
|
436 |
self addToParameter: char. |
|
437 |
^ self |
|
438 |
]. |
|
949 | 439 |
(char == $l |
440 |
or:[char == $h]) ifTrue: [ |
|
441 |
"/ (parameters at: 1) = 1 ifTrue: [app_cur_keys:(char == $h)]. |
|
442 |
"/ (parameters at: 1) = 2 ifTrue: [mode132:(char == $h)]. |
|
443 |
"/ (parameters at: 1) = 4 ifTrue: [smoothScroll:(char == $h)]. |
|
444 |
"/ (parameters at: 1) = 5 ifTrue: [reverseVideo:(char == $h)]. |
|
445 |
"/ (parameters at: 1) = 6 ifTrue: [decom:(char == $h)]. |
|
446 |
(parameters at: 1) = 7 ifTrue: [self autoMargin:(char == $h)]. |
|
951 | 447 |
^ self endOfSequence |
927 | 448 |
]. |
939 | 449 |
^ self doNothing |
927 | 450 |
]. |
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
451 |
|
944 | 452 |
state == #gotXTERMCSI ifTrue:[ |
453 |
"/ Currently, we are in ESC-] state. |
|
454 |
"/ Decide what to do on the basis of the parameter char. |
|
455 |
^ self doNothing |
|
456 |
]. |
|
457 |
||
927 | 458 |
self doNothing |
459 |
||
956 | 460 |
"Modified: / 13.6.1998 / 18:13:25 / cg" |
920 | 461 |
! ! |
462 |
||
930 | 463 |
!VT100TerminalView methodsFor:'queries'! |
464 |
||
465 |
terminalType |
|
466 |
^ #vt100 |
|
467 |
||
468 |
"Created: / 10.6.1998 / 16:22:39 / cg" |
|
469 |
! ! |
|
470 |
||
920 | 471 |
!VT100TerminalView class methodsFor:'documentation'! |
472 |
||
473 |
version |
|
976 | 474 |
^ '$Header: /cvs/stx/stx/libwidg2/VT100TerminalView.st,v 1.16 1998-06-20 15:36:52 cg Exp $' |
920 | 475 |
! ! |