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