author | tz |
Thu, 23 Jul 1998 15:05:44 +0200 | |
changeset 1005 | 816ee29d2de4 |
parent 1004 | 8742d3af41a4 |
child 1009 | 4cfed4bac6f0 |
permissions | -rw-r--r-- |
914 | 1 |
TextCollector subclass:#TerminalView |
943 | 2 |
instanceVariableNames:'inStream outStream readerProcess shellPid kbdSequences |
3 |
escapeSequenceTree currentSequence currentTree kbdMap |
|
946 | 4 |
escapeLeadingChars numberOfColumns numberOfLines |
997 | 5 |
shellTerminateAction rangeStartLine rangeEndLine state' |
943 | 6 |
classVariableNames:'' |
7 |
poolDictionaries:'' |
|
8 |
category:'Views-TerminalViews' |
|
914 | 9 |
! |
10 |
||
11 |
!TerminalView class methodsFor:'documentation'! |
|
12 |
||
13 |
documentation |
|
14 |
" |
|
916 | 15 |
I provide terminal functionality, by forking a command interpreter |
16 |
and comunicating with it via a pty. |
|
17 |
I am abstract - concrete terminal characteristics are defined |
|
18 |
by concrete subclasses (see VT52TerminalView). |
|
914 | 19 |
|
20 |
[author:] |
|
21 |
Claus Gittinger |
|
915 | 22 |
|
23 |
[start with:] |
|
24 |
VT52TerminalView openShell |
|
919 | 25 |
VT100TerminalView openShell |
914 | 26 |
" |
27 |
! ! |
|
28 |
||
972 | 29 |
!TerminalView class methodsFor:'opening'! |
914 | 30 |
|
928 | 31 |
open |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
32 |
^ self openShell |
928 | 33 |
|
34 |
" |
|
35 |
VT100TerminalView open |
|
36 |
" |
|
37 |
||
38 |
"Created: / 10.6.1998 / 15:47:25 / cg" |
|
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
39 |
"Modified: / 9.7.1998 / 17:55:37 / cg" |
928 | 40 |
! |
41 |
||
914 | 42 |
openDummy |
972 | 43 |
"for testing purposes only - opens a dummy tty-view, which simply |
44 |
echoes whatever is typed in" |
|
45 |
||
914 | 46 |
|in vt52| |
47 |
||
48 |
vt52 := self new. |
|
49 |
in := ForwardingStream on:''. |
|
50 |
||
51 |
in fwdStream:vt52. |
|
52 |
vt52 inStream:in. |
|
53 |
vt52 outStream:in. |
|
54 |
vt52 open |
|
55 |
||
56 |
" |
|
57 |
self openDummy |
|
58 |
" |
|
59 |
! |
|
60 |
||
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
61 |
openOnCommand:aCommandString |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
62 |
"start a command on a pseudo-TTY, open a terminalView on it |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
63 |
(i.e. this is kind of an xterm)" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
64 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
65 |
^ self openOnCommand:aCommandString onExit:[] |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
66 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
67 |
" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
68 |
VT100TerminalView openOnCommand:'ls -l' |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
69 |
" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
70 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
71 |
"Created: / 9.7.1998 / 17:50:53 / cg" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
72 |
"Modified: / 9.7.1998 / 17:57:41 / cg" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
73 |
! |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
74 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
75 |
openOnCommand:aCommandString onExit:aBlock |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
76 |
"start a command on a pseudo-TTY, open a terminalView on its output |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
77 |
(i.e. this is kind of an xterm). |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
78 |
When the command finishes, evaluate aBlock." |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
79 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
80 |
|in top scr vt52| |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
81 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
82 |
top := StandardSystemView new. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
83 |
scr := ScrollableView for:self in:top. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
84 |
scr origin:0.0@0.0 corner:1.0@1.0. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
85 |
vt52 := scr scrolledView. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
86 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
87 |
vt52 startCommand:aCommandString. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
88 |
vt52 shellTerminateAction:[ |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
89 |
top label:('finished: "' , aCommandString , '"'). aBlock value |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
90 |
]. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
91 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
92 |
top extent:(scr preferredExtent). |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
93 |
top label:('executing: "' , aCommandString , '"'). |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
94 |
top open. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
95 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
96 |
^ vt52 |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
97 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
98 |
" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
99 |
VT100TerminalView openOnCommand:'ls -lR' |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
100 |
VT100TerminalView openOnCommand:'vi /etc/hosts' |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
101 |
" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
102 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
103 |
"Created: / 9.7.1998 / 17:54:34 / cg" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
104 |
"Modified: / 9.7.1998 / 18:03:31 / cg" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
105 |
! |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
106 |
|
972 | 107 |
openOnInput:inStream output:outStream |
108 |
"open a terminalView on the given streams (which are typically some |
|
109 |
kind of socket). Keys pressed are sent to inStream, text appearing |
|
110 |
from outStream are displayed in the terminal view. |
|
111 |
This can be used to implement things like rlogin |
|
112 |
or telnet views (if connected to a modem, a call-unix can also be |
|
113 |
implemented this way)." |
|
114 |
||
115 |
|in top scr vt52| |
|
116 |
||
117 |
top := StandardSystemView new. |
|
118 |
scr := ScrollableView for:self in:top. |
|
119 |
scr origin:0.0@0.0 corner:1.0@1.0. |
|
120 |
vt52 := scr scrolledView. |
|
121 |
||
122 |
vt52 inStream:inStream. |
|
123 |
vt52 outStream:outStream. |
|
974 | 124 |
vt52 startReaderProcess. |
972 | 125 |
|
126 |
top extent:(scr preferredExtent). |
|
127 |
top label:'shell'. |
|
128 |
top open. |
|
129 |
^ top |
|
974 | 130 |
|
131 |
"Modified: / 20.6.1998 / 17:32:38 / cg" |
|
972 | 132 |
! |
133 |
||
914 | 134 |
openShell |
972 | 135 |
"start a shell on a pseudo-TTY, open a terminalView on it |
136 |
(i.e. this is kind of an xterm)" |
|
137 |
||
997 | 138 |
^ self openShellIn:nil |
992 | 139 |
|
140 |
" |
|
141 |
VT100TerminalView openShell |
|
142 |
" |
|
143 |
||
997 | 144 |
"Modified: / 21.7.1998 / 18:24:55 / cg" |
992 | 145 |
! |
146 |
||
147 |
openShellIn:aDirectory |
|
148 |
"start a shell on a pseudo-TTY, open a terminalView on it |
|
149 |
(i.e. this is kind of an xterm)" |
|
150 |
||
914 | 151 |
|in top scr vt52| |
152 |
||
153 |
top := StandardSystemView new. |
|
948 | 154 |
scr := ScrollableView for:self in:top. |
914 | 155 |
scr origin:0.0@0.0 corner:1.0@1.0. |
156 |
vt52 := scr scrolledView. |
|
157 |
||
992 | 158 |
vt52 startShellIn:aDirectory. |
946 | 159 |
vt52 shellTerminateAction:[top destroy]. |
160 |
||
940 | 161 |
top extent:(scr preferredExtent). |
162 |
top label:'shell'. |
|
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
163 |
top open. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
164 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
165 |
^ vt52 |
914 | 166 |
|
167 |
" |
|
992 | 168 |
VT100TerminalView openShellIn:'/etc' |
914 | 169 |
" |
946 | 170 |
|
992 | 171 |
"Created: / 20.7.1998 / 18:28:15 / cg" |
172 |
"Modified: / 20.7.1998 / 18:28:31 / cg" |
|
914 | 173 |
! ! |
174 |
||
972 | 175 |
!TerminalView class methodsFor:'queries'! |
176 |
||
177 |
isVisualStartable |
|
178 |
"returns whether this application class can be started via #open" |
|
179 |
||
180 |
self == TerminalView ifTrue:[^ false]. |
|
181 |
^ true |
|
182 |
||
183 |
"Created: / 10.6.1998 / 15:48:43 / cg" |
|
184 |
! ! |
|
185 |
||
914 | 186 |
!TerminalView methodsFor:'accessing'! |
187 |
||
188 |
inStream |
|
189 |
"return the value of the instance variable 'inStream' (automatically generated)" |
|
190 |
||
191 |
^ inStream! |
|
192 |
||
193 |
inStream:something |
|
194 |
"set the value of the instance variable 'inStream' (automatically generated)" |
|
195 |
||
196 |
inStream := something.! |
|
197 |
||
198 |
outStream |
|
199 |
"return the value of the instance variable 'outStream' (automatically generated)" |
|
200 |
||
201 |
^ outStream! |
|
202 |
||
203 |
outStream:something |
|
204 |
"set the value of the instance variable 'outStream' (automatically generated)" |
|
205 |
||
946 | 206 |
outStream := something.! |
207 |
||
1004 | 208 |
readerProcess |
209 |
"return the value of the instance variable 'readerProcess' (automatically generated)" |
|
210 |
||
211 |
^ readerProcess |
|
212 |
! |
|
213 |
||
946 | 214 |
shellTerminateAction:aBlock |
215 |
"set the block which is evaluated when the shell terminates. |
|
216 |
Can be used to close down the application in this case." |
|
217 |
||
218 |
shellTerminateAction := aBlock. |
|
219 |
||
220 |
"Created: / 12.6.1998 / 17:02:58 / cg" |
|
221 |
! ! |
|
914 | 222 |
|
223 |
!TerminalView methodsFor:'cursor handling'! |
|
224 |
||
225 |
cursorCol:col |
|
226 |
"check of col is a valid cursor position; return a new col-nr if not. |
|
227 |
Here, the linelength is enforced" |
|
228 |
||
926 | 229 |
^ super cursorCol:(col min:numberOfColumns) |
914 | 230 |
|
926 | 231 |
"Modified: / 10.6.1998 / 15:09:34 / cg" |
914 | 232 |
! |
233 |
||
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
234 |
cursorDown:n |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
235 |
cursorLine + n > list size ifTrue:[ |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
236 |
list := list , (Array new:n). |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
237 |
self textChanged. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
238 |
]. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
239 |
super cursorDown:n |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
240 |
|
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
241 |
"Modified: / 10.6.1998 / 17:18:41 / cg" |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
242 |
"Created: / 10.6.1998 / 17:18:50 / cg" |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
243 |
! |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
244 |
|
914 | 245 |
cursorLine:l col:col |
246 |
"check of col is a valid cursor position; return a new col-nr if not. |
|
247 |
Here, the linelength is enforced" |
|
248 |
||
926 | 249 |
^ super cursorLine:l col:(col min:numberOfColumns) |
914 | 250 |
|
926 | 251 |
"Modified: / 10.6.1998 / 15:09:38 / cg" |
914 | 252 |
! |
253 |
||
968
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
254 |
cursorMovementAllowed |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
255 |
"return true, if the user may move the cursor around |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
256 |
(via button-click, or cursor-key with selection). |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
257 |
Here false is returned - the cursor is only moved by |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
258 |
cursor positioning escape sequences arriving from the |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
259 |
stream." |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
260 |
|
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
261 |
^ false |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
262 |
|
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
263 |
"Created: / 18.6.1998 / 14:12:02 / cg" |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
264 |
! |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
265 |
|
914 | 266 |
validateCursorCol:col inLine:line |
267 |
"check of col is a valid cursor position; return a new col-nr if not. |
|
268 |
Here, the linelength is enforced" |
|
269 |
||
926 | 270 |
^ col min:numberOfColumns |
914 | 271 |
|
926 | 272 |
"Modified: / 10.6.1998 / 15:09:41 / cg" |
914 | 273 |
! ! |
274 |
||
275 |
!TerminalView methodsFor:'event handling'! |
|
276 |
||
951 | 277 |
computeNumberOfLinesShown |
278 |
|prevNLines prevNCols| |
|
279 |
||
280 |
prevNCols := (innerWidth // font width). |
|
281 |
prevNLines := nFullLinesShown. |
|
282 |
||
283 |
super computeNumberOfLinesShown. |
|
284 |
||
285 |
((innerWidth // font width) ~~ prevNCols |
|
286 |
or:[prevNLines ~~ nFullLinesShown]) ifTrue:[ |
|
287 |
self defineWindowSize. |
|
288 |
] |
|
289 |
||
290 |
"Created: / 12.6.1998 / 22:34:39 / cg" |
|
979 | 291 |
"Modified: / 20.6.1998 / 19:45:28 / cg" |
951 | 292 |
! |
293 |
||
943 | 294 |
defineWindowSize |
295 |
inStream notNil ifTrue:[ |
|
964
43d6e33a4240
keep cursor off while more input is arriving.
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
296 |
(OperatingSystem |
943 | 297 |
setWindowSizeOnFileDescriptor:(inStream fileDescriptor) |
298 |
width:(innerWidth // font width) |
|
964
43d6e33a4240
keep cursor off while more input is arriving.
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
299 |
height:(nFullLinesShown)) ifFalse:[ |
43d6e33a4240
keep cursor off while more input is arriving.
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
300 |
"/ Transcript showCR:'VT100: cannot change windowSize'. |
43d6e33a4240
keep cursor off while more input is arriving.
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
301 |
]. |
951 | 302 |
numberOfLines := nFullLinesShown. |
979 | 303 |
"/ Transcript showCR:'VT100: changed len to ', numberOfLines printString. |
943 | 304 |
]. |
305 |
shellPid notNil ifTrue:[ |
|
306 |
OperatingSystem sendSignal:OperatingSystem sigWINCH to:shellPid |
|
307 |
] |
|
308 |
||
309 |
"Created: / 11.6.1998 / 22:51:39 / cg" |
|
979 | 310 |
"Modified: / 20.6.1998 / 20:29:13 / cg" |
943 | 311 |
! |
312 |
||
914 | 313 |
keyPress:aKey x:x y:y |
314 |
|rest rawKey seq| |
|
315 |
||
316 |
inStream isNil ifTrue:[^ self]. |
|
317 |
||
931 | 318 |
"/ Transcript showCR:'----'; show:'key:' ; showCR:aKey printString. |
914 | 319 |
|
320 |
aKey isCharacter ifTrue:[ |
|
321 |
"/ send it down to inStream ... |
|
322 |
inStream nextPut:aKey. |
|
323 |
^ self |
|
324 |
]. |
|
325 |
||
921 | 326 |
aKey == #Tab ifTrue:[ |
931 | 327 |
"/ Transcript show:'->' ; showCR:Character tab storeString. |
921 | 328 |
inStream nextPut:Character tab. |
329 |
^ self |
|
330 |
]. |
|
331 |
||
914 | 332 |
seq := kbdSequences at:aKey ifAbsent:nil. |
333 |
seq notNil ifTrue:[ |
|
931 | 334 |
"/ Transcript show:'->' ; showCR:seq storeString. |
914 | 335 |
inStream nextPutAll:(seq withEscapes). |
336 |
^ self |
|
337 |
]. |
|
338 |
||
339 |
rawKey := device keyboardMap keyAtValue:aKey ifAbsent:aKey. |
|
340 |
seq := kbdSequences at:rawKey ifAbsent:nil. |
|
341 |
seq notNil ifTrue:[ |
|
931 | 342 |
"/ Transcript show:'->' ; showCR:seq storeString. |
914 | 343 |
inStream nextPutAll:(seq withEscapes). |
344 |
^ self |
|
345 |
]. |
|
346 |
||
347 |
(rawKey startsWith:'Ctrl') ifTrue:[ |
|
348 |
rest := rawKey copyFrom:5. |
|
349 |
rest size == 1 ifTrue:[ |
|
350 |
rest := rest at:1. |
|
351 |
(rest >= $a and:[rest <= $z]) ifTrue:[ |
|
931 | 352 |
"/ Transcript show:'->' ; showCR:(Character value:(rest - $a + 1)) storeString. |
914 | 353 |
inStream nextPut:(Character value:(rest - $a + 1)). |
354 |
^ self |
|
355 |
]. |
|
356 |
(rest >= $A and:[rest <= $Z]) ifTrue:[ |
|
931 | 357 |
"/ Transcript show:'->' ; showCR:(Character value:(rest - $a + 1)) storeString. |
914 | 358 |
inStream nextPut:(Character value:(rest - $A + 1)). |
359 |
^ self |
|
360 |
]. |
|
361 |
] |
|
362 |
]. |
|
363 |
||
934 | 364 |
(rawKey startsWith:'Control') ifTrue:[ |
365 |
^ self |
|
366 |
]. |
|
367 |
(rawKey startsWith:'Shift') ifTrue:[ |
|
368 |
^ self |
|
369 |
]. |
|
370 |
(rawKey startsWith:'Alt') ifTrue:[ |
|
371 |
^ self |
|
372 |
]. |
|
373 |
(rawKey startsWith:'Cmd') ifTrue:[ |
|
950 | 374 |
^ super keyPress:aKey x:x y:y |
934 | 375 |
]. |
376 |
||
377 |
Transcript show:'unhandled: '; showCR:rawKey. |
|
914 | 378 |
|
950 | 379 |
"Modified: / 12.6.1998 / 22:16:50 / cg" |
914 | 380 |
! |
381 |
||
382 |
shellTerminated |
|
383 |
self closeDownShell. |
|
946 | 384 |
shellTerminateAction notNil ifTrue:[ |
385 |
shellTerminateAction value |
|
386 |
] ifFalse:[ |
|
387 |
"/ may be removed ... |
|
388 |
self warn:'shell terminated'. |
|
389 |
] |
|
390 |
||
391 |
"Modified: / 12.6.1998 / 17:03:26 / cg" |
|
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
392 |
! |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
393 |
|
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
394 |
sizeChanged:how |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
395 |
super sizeChanged:how. |
943 | 396 |
self defineWindowSize. |
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
397 |
|
943 | 398 |
"Modified: / 11.6.1998 / 22:51:48 / cg" |
914 | 399 |
! ! |
400 |
||
401 |
!TerminalView methodsFor:'functions'! |
|
402 |
||
403 |
doBackspace |
|
404 |
self cursorLeft. |
|
405 |
self replaceCharAtCursor:(Character space). |
|
406 |
self cursorLeft. |
|
407 |
||
931 | 408 |
"Modified: / 10.6.1998 / 17:09:12 / cg" |
914 | 409 |
! |
410 |
||
926 | 411 |
doClearDisplay |
1000 | 412 |
self doClearEntireScreen. |
413 |
||
414 |
"Modified: / 21.7.1998 / 20:05:35 / cg" |
|
415 |
! |
|
416 |
||
417 |
doClearEntireScreen |
|
926 | 418 |
firstLineShown to:(list size) do:[:l | |
419 |
self at:l put:'' |
|
420 |
]. |
|
922 | 421 |
|
1000 | 422 |
"Modified: / 21.7.1998 / 20:00:19 / cg" |
423 |
"Created: / 21.7.1998 / 20:05:24 / cg" |
|
926 | 424 |
! |
425 |
||
1000 | 426 |
doClearFromBeginningOfLine |
427 |
|l| |
|
428 |
||
429 |
l := self listAt:cursorLine. |
|
430 |
l notNil ifTrue:[ |
|
431 |
(l size >= (cursorCol-1)) ifTrue:[ |
|
432 |
l := l copy from:1 to:cursorCol-1 put:(Character space). |
|
433 |
] ifFalse:[ |
|
434 |
l := nil. |
|
435 |
]. |
|
436 |
self withoutRedrawAt:cursorLine put:l. |
|
437 |
self invalidateLine:cursorLine |
|
438 |
"/ self at:cursorLine put:l. |
|
439 |
] |
|
440 |
||
441 |
"Modified: / 20.6.1998 / 19:10:21 / cg" |
|
442 |
"Created: / 21.7.1998 / 20:10:58 / cg" |
|
443 |
! |
|
444 |
||
445 |
doClearFromBeginningOfScreen |
|
446 |
self doClearFromBeginningOfLine. |
|
447 |
cursorLine-1 to:firstLineShown do:[:l | |
|
922 | 448 |
self at:l put:'' |
449 |
]. |
|
450 |
||
926 | 451 |
"Modified: / 10.6.1998 / 14:45:43 / cg" |
1000 | 452 |
"Created: / 21.7.1998 / 20:08:29 / cg" |
926 | 453 |
! |
454 |
||
455 |
doClearToEndOfLine |
|
456 |
|l| |
|
457 |
||
458 |
l := self listAt:cursorLine. |
|
931 | 459 |
(l size >= (cursorCol-1)) ifTrue:[ |
951 | 460 |
l notNil ifTrue:[ |
461 |
l := l copyTo:cursorCol-1. |
|
979 | 462 |
self withoutRedrawAt:cursorLine put:l. |
463 |
self invalidateLine:cursorLine |
|
464 |
"/ self at:cursorLine put:l. |
|
951 | 465 |
] |
926 | 466 |
] |
467 |
||
468 |
"Created: / 10.6.1998 / 14:45:01 / cg" |
|
979 | 469 |
"Modified: / 20.6.1998 / 19:10:21 / cg" |
914 | 470 |
! |
471 |
||
1000 | 472 |
doClearToEndOfScreen |
473 |
self doClearToEndOfLine. |
|
474 |
cursorLine+1 to:(list size) do:[:l | |
|
475 |
self at:l put:'' |
|
476 |
]. |
|
477 |
||
478 |
"Modified: / 10.6.1998 / 14:45:43 / cg" |
|
479 |
"Created: / 21.7.1998 / 20:06:14 / cg" |
|
480 |
! |
|
481 |
||
926 | 482 |
doCursorDown:n |
979 | 483 |
|wasOn rEnd| |
926 | 484 |
|
979 | 485 |
"/ rangeEndLine == numberOfLines ifTrue:[ |
486 |
"/ ^ super cursorDown:n |
|
487 |
"/ ]. |
|
488 |
cursorLine + 1 - firstLineShown + n <= rangeEndLine ifTrue:[ |
|
951 | 489 |
"/ no special action req'd |
490 |
^ super cursorDown:n |
|
491 |
]. |
|
979 | 492 |
|
951 | 493 |
n timesRepeat:[ |
494 |
wasOn := self hideCursor. |
|
979 | 495 |
rEnd := rangeEndLine+firstLineShown-1. |
496 |
cursorLine == rEnd ifTrue:[ |
|
497 |
self deleteLine:(rangeStartLine+firstLineShown-1). |
|
498 |
self insertLine:'' before:rEnd. |
|
951 | 499 |
] ifFalse:[ |
500 |
super cursorDown |
|
501 |
]. |
|
979 | 502 |
wasOn ifTrue:[self showCursor]. "/ self makeCursorVisibleAndShowCursor:wasOn. |
951 | 503 |
] |
504 |
||
979 | 505 |
"Modified: / 20.6.1998 / 20:29:39 / cg" |
926 | 506 |
! |
507 |
||
914 | 508 |
doCursorHome |
938 | 509 |
self cursorVisibleLine:1 col:1 |
510 |
"/ super cursorHome |
|
511 |
||
512 |
"Modified: / 10.6.1998 / 20:47:31 / cg" |
|
914 | 513 |
! |
514 |
||
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
515 |
doCursorLeft:n |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
516 |
n timesRepeat:[ |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
517 |
super cursorLeft |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
518 |
] |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
519 |
|
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
520 |
"Created: / 11.6.1998 / 22:30:00 / cg" |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
521 |
! |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
522 |
|
914 | 523 |
doCursorNewLine |
931 | 524 |
super cursorDown:1 |
525 |
||
526 |
"Modified: / 10.6.1998 / 16:55:57 / cg" |
|
914 | 527 |
! |
528 |
||
529 |
doCursorReturn |
|
530 |
super cursorToBeginOfLine |
|
531 |
! |
|
532 |
||
926 | 533 |
doCursorRight:n |
534 |
self cursorCol:(cursorCol + n) |
|
535 |
||
536 |
"Created: / 10.6.1998 / 15:10:08 / cg" |
|
537 |
! |
|
538 |
||
951 | 539 |
doCursorUp:n |
979 | 540 |
|wasOn rStart| |
926 | 541 |
|
979 | 542 |
"/ rangeStartLine == 1 ifTrue:[ |
543 |
"/ ^ super cursorUp:n |
|
544 |
"/ ]. |
|
545 |
cursorLine + 1 - firstLineShown - n >= rangeStartLine ifTrue:[ |
|
951 | 546 |
"/ no special action req'd |
547 |
^ super cursorUp:n |
|
548 |
]. |
|
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
549 |
n timesRepeat:[ |
951 | 550 |
wasOn := self hideCursor. |
979 | 551 |
rStart := rangeStartLine+firstLineShown-1. |
552 |
cursorLine == rStart ifTrue:[ |
|
553 |
(rangeEndLine+firstLineShown-1) <= list size ifTrue:[ |
|
554 |
self deleteLine:(rangeEndLine+firstLineShown-1). |
|
555 |
self insertLine:'' before:rStart. |
|
556 |
]. |
|
951 | 557 |
] ifFalse:[ |
558 |
super cursorUp |
|
559 |
]. |
|
560 |
self makeCursorVisibleAndShowCursor:wasOn. |
|
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
561 |
] |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
562 |
|
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
563 |
"Created: / 11.6.1998 / 22:29:46 / cg" |
979 | 564 |
"Modified: / 20.6.1998 / 20:30:34 / cg" |
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
565 |
! |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
566 |
|
926 | 567 |
doSendInterrupt |
568 |
OperatingSystem sendSignal:(OperatingSystem sigINT) to:shellPid negated. |
|
569 |
||
934 | 570 |
"Modified: / 10.6.1998 / 17:49:49 / cg" |
914 | 571 |
! ! |
572 |
||
573 |
!TerminalView methodsFor:'initialization'! |
|
574 |
||
575 |
closeDownShell |
|
1005 | 576 |
|pid sensor| |
926 | 577 |
|
578 |
(pid := shellPid) notNil ifTrue:[ |
|
934 | 579 |
"/ Transcript print:'killing shell pid='; showCR:pid. |
580 |
||
926 | 581 |
OperatingSystem terminateProcessGroup:pid. |
582 |
OperatingSystem terminateProcess:pid. |
|
925 | 583 |
Delay waitForSeconds:1. |
584 |
shellPid notNil ifTrue:[ |
|
926 | 585 |
OperatingSystem killProcessGroup:pid. |
586 |
OperatingSystem killProcess:pid. |
|
925 | 587 |
shellPid := nil. |
588 |
]. |
|
926 | 589 |
OperatingSystem closePid:pid. |
914 | 590 |
]. |
591 |
||
592 |
readerProcess notNil ifTrue:[ |
|
593 |
readerProcess terminate. |
|
997 | 594 |
"/ give it a chance to really terminate |
595 |
Processor yield. |
|
914 | 596 |
readerProcess := nil |
597 |
]. |
|
598 |
inStream notNil ifTrue:[ |
|
599 |
inStream close. |
|
600 |
inStream := nil |
|
601 |
]. |
|
602 |
outStream notNil ifTrue:[ |
|
603 |
outStream close. |
|
604 |
outStream := nil |
|
605 |
]. |
|
924 | 606 |
|
997 | 607 |
"/ flush any leftover input-processing events |
1005 | 608 |
(sensor := self sensor) notNil ifTrue:[ |
609 |
sensor flushEventsFor:self withType:#processInput:n:. |
|
610 |
] |
|
997 | 611 |
"Modified: / 21.7.1998 / 19:00:13 / cg" |
914 | 612 |
! |
613 |
||
614 |
destroy |
|
615 |
self closeDownShell. |
|
616 |
super destroy |
|
617 |
! |
|
618 |
||
619 |
escapeSequences:codes |
|
620 |
|tree| |
|
621 |
||
622 |
tree isNil ifTrue:[tree := escapeSequenceTree := IdentityDictionary new]. |
|
623 |
||
624 |
codes do:[:specEntry | |
|
625 |
|sequence function| |
|
626 |
||
627 |
sequence := (specEntry at:1) withEscapes. |
|
628 |
function := specEntry at:2. |
|
629 |
||
630 |
tree := escapeSequenceTree. |
|
631 |
||
632 |
sequence keysAndValuesDo:[:idx :char | |
|
633 |
|followup| |
|
634 |
||
635 |
idx == sequence size ifTrue:[ |
|
636 |
tree at:char put:function |
|
637 |
] ifFalse:[ |
|
638 |
followup := tree at:char ifAbsent:nil. |
|
639 |
followup isNil ifTrue:[ |
|
640 |
tree at:char put:(followup := IdentityDictionary new). |
|
641 |
]. |
|
642 |
tree := followup |
|
643 |
] |
|
644 |
] |
|
645 |
]. |
|
918 | 646 |
escapeLeadingChars := escapeSequenceTree keys asSet. |
647 |
escapeLeadingChars add:(Character cr). |
|
648 |
escapeLeadingChars add:(Character return). |
|
649 |
escapeLeadingChars add:(Character backspace). |
|
650 |
||
651 |
escapeLeadingChars := escapeLeadingChars asArray |
|
652 |
||
653 |
"Modified: / 9.6.1998 / 19:43:12 / cg" |
|
914 | 654 |
! |
655 |
||
656 |
initialize |
|
657 |
super initialize. |
|
658 |
||
659 |
showMatchingParenthesis := false. |
|
660 |
insertMode := false. |
|
936 | 661 |
alwaysAppendAtEnd := false. |
944 | 662 |
collectSize := 100. |
977 | 663 |
st80Mode := false. |
664 |
trimBlankLines := true. |
|
914 | 665 |
|
926 | 666 |
numberOfColumns := 80. |
979 | 667 |
numberOfLines := 24. |
954 | 668 |
rangeStartLine := 1. |
669 |
rangeEndLine := numberOfLines. |
|
926 | 670 |
|
914 | 671 |
self initializeKeyboardSequences. |
672 |
list := OrderedCollection new:24 withAll:''. |
|
673 |
||
674 |
self initializeKeyboardMap. |
|
675 |
||
676 |
" |
|
677 |
VT52TerminalView openShell |
|
926 | 678 |
VT100TerminalView openShell |
914 | 679 |
" |
926 | 680 |
|
979 | 681 |
"Modified: / 20.6.1998 / 20:06:49 / cg" |
914 | 682 |
! |
683 |
||
684 |
initializeKeyboardMap |
|
685 |
|ctrlKeys cmdKeys| |
|
686 |
||
687 |
"/ setup my own keyboardMap, where control-keys are |
|
688 |
"/ not translated. |
|
689 |
kbdMap := device keyboardMap copy. |
|
690 |
||
691 |
ctrlKeys := kbdMap keys select:[:key | key startsWith:'Ctrl']. |
|
692 |
ctrlKeys do:[:key | kbdMap removeKey:key]. |
|
950 | 693 |
|
914 | 694 |
cmdKeys := kbdMap keys select:[:key | key startsWith:'Cmd']. |
950 | 695 |
cmdKeys do:[:key | |
696 |
(#(Copy Paste SaveAs Print) includes:(kbdMap at:key)) ifFalse:[ |
|
697 |
kbdMap removeKey:key |
|
698 |
] |
|
699 |
]. |
|
914 | 700 |
|
701 |
kbdMap removeKey:#Delete ifAbsent:[]. |
|
702 |
kbdMap removeKey:#BackSpace ifAbsent:[]. |
|
703 |
||
704 |
" |
|
705 |
VT52TerminalView openShell |
|
706 |
" |
|
950 | 707 |
|
708 |
"Modified: / 12.6.1998 / 22:18:23 / cg" |
|
914 | 709 |
! |
710 |
||
711 |
initializeKeyboardSequences |
|
712 |
self subclassResponsibility. |
|
713 |
! |
|
714 |
||
715 |
keyboardMap |
|
934 | 716 |
"return my keyboard map. This has control keys removed and |
717 |
those will be passed unchanged to the shell" |
|
718 |
||
914 | 719 |
^ kbdMap |
934 | 720 |
|
721 |
"Modified: / 10.6.1998 / 17:46:59 / cg" |
|
914 | 722 |
! |
723 |
||
724 |
startReaderProcess |
|
934 | 725 |
"Start a reader process, which looks for the commands output, |
726 |
and sends me #peocessInput:n: events whenever something arrives." |
|
727 |
||
914 | 728 |
readerProcess isNil ifTrue:[ |
729 |
readerProcess := [ |
|
730 |
[ |
|
947 | 731 |
self waitUntilVisible. |
732 |
||
940 | 733 |
Stream streamErrorSignal handle:[:ex | |
734 |
Transcript showCR:ex errorString. |
|
735 |
Transcript showCR:OperatingSystem lastErrorString. |
|
736 |
] do:[ |
|
926 | 737 |
[true] whileTrue:[ |
738 |
Object abortSignal handle:[:ex | |
|
739 |
self showCursor. |
|
740 |
] do:[ |
|
948 | 741 |
|buffer n| |
742 |
||
926 | 743 |
outStream readWait. |
945 | 744 |
(self sensor hasKeyPressEventFor:self) ifTrue:[ |
999 | 745 |
(self sensor userEventCount > 10) ifTrue:[ |
997 | 746 |
"/ give terminalView a chance to |
747 |
"/ send out the character. |
|
748 |
Delay waitForSeconds:0.1. |
|
749 |
] |
|
926 | 750 |
] ifFalse:[ |
945 | 751 |
buffer := String new:1024. |
752 |
n := outStream nextAvailableBytes:1024 into:buffer startingAt:1. |
|
753 |
||
754 |
n > 0 ifTrue:[ |
|
755 |
self pushEvent:#processInput:n: with:buffer with:n. |
|
999 | 756 |
(self sensor userEventCount > 50) ifTrue:[ |
757 |
[self sensor userEventCount > 10] whileTrue:[ |
|
997 | 758 |
"/ give terminalView a chance to |
759 |
"/ catch up. |
|
760 |
Delay waitForSeconds:0.1. |
|
761 |
] |
|
762 |
]. |
|
945 | 763 |
] ifFalse:[ |
764 |
n == 0 ifTrue:[ |
|
765 |
outStream atEnd ifTrue:[ |
|
766 |
outStream close. outStream := nil. |
|
767 |
inStream close. inStream := nil. |
|
768 |
||
769 |
Processor activeProcess terminate. |
|
770 |
] |
|
926 | 771 |
] |
772 |
] |
|
914 | 773 |
] |
774 |
] |
|
775 |
] |
|
776 |
] |
|
777 |
] valueOnUnwindDo:[ |
|
778 |
readerProcess := nil |
|
779 |
] |
|
997 | 780 |
] fork. "/ forkAt:9. |
781 |
readerProcess name:'pty reader'. |
|
914 | 782 |
] |
783 |
||
784 |
" |
|
934 | 785 |
VT100TerminalView openShell |
914 | 786 |
" |
926 | 787 |
|
999 | 788 |
"Modified: / 21.7.1998 / 19:36:27 / cg" |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
789 |
! ! |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
790 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
791 |
!TerminalView methodsFor:'initialization-shell'! |
914 | 792 |
|
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
793 |
startCommand:aCommand |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
794 |
"start a command on a pseudo terminal. If the command arg is nil, |
992 | 795 |
a shell is started. The command is started in the current directory. |
796 |
Also fork a reader process, to read the shells output and |
|
797 |
tell me, whenever something arrives" |
|
798 |
||
799 |
^ self startCommand:aCommand in:nil |
|
800 |
||
801 |
"Modified: / 20.7.1998 / 18:30:24 / cg" |
|
802 |
! |
|
803 |
||
804 |
startCommand:aCommand in:aDirectory |
|
805 |
"start a command on a pseudo terminal. If the command arg is nil, |
|
806 |
a shell is started. If aDirectory is not nil, the command is |
|
807 |
executed in that directory. |
|
934 | 808 |
Also fork a reader process, to read the shells output and |
948 | 809 |
tell me, whenever something arrives" |
934 | 810 |
|
914 | 811 |
|p slaveFD execFdArray blocked exitStatus| |
812 |
||
958
84710fbdfb28
create my view before starting a shell (to pass down windowID).
Claus Gittinger <cg@exept.de>
parents:
957
diff
changeset
|
813 |
self create. "/ need my windowID (to pass down in environment) |
84710fbdfb28
create my view before starting a shell (to pass down windowID).
Claus Gittinger <cg@exept.de>
parents:
957
diff
changeset
|
814 |
|
914 | 815 |
p := ExternalStream makePTYPair. |
816 |
p isNil ifTrue:[ |
|
915 | 817 |
self warn:'cannot open pty'. |
914 | 818 |
^ self. |
819 |
]. |
|
820 |
||
821 |
"/ p at:1 is the master; |
|
822 |
"/ p at:2 is the slave |
|
823 |
inStream := outStream := (p at:1). |
|
824 |
inStream buffered:false. |
|
825 |
||
943 | 826 |
self defineWindowSize. |
827 |
||
914 | 828 |
"/ fork a shell process on the slave-side |
829 |
slaveFD := (p at:2) fileDescriptor. |
|
830 |
||
831 |
execFdArray := Array with:slaveFD with:slaveFD with:slaveFD. |
|
832 |
||
833 |
blocked := OperatingSystem blockInterrupts. |
|
834 |
||
835 |
shellPid := Processor |
|
836 |
monitor:[ |
|
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
837 |
|e shell cmd args| |
929 | 838 |
|
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
839 |
e := Dictionary new. |
957
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
840 |
e at:'TERM' put:(self terminalType). |
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
841 |
e at:'LINES' put:(numberOfLines printString). |
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
842 |
e at:'COLUMNS' put:(numberOfColumns printString). |
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
843 |
drawableId notNil ifTrue:[ |
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
844 |
e at:'WINDOWID' put:(drawableId address printString). |
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
845 |
]. |
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
846 |
|
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
847 |
aCommand isNil ifTrue:[ |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
848 |
shell := OperatingSystem getEnvironment:'SHELL'. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
849 |
shell size == 0 ifTrue:[ |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
850 |
shell := '/bin/sh'. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
851 |
]. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
852 |
cmd := shell asFilename baseName. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
853 |
args := (Array with:cmd). |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
854 |
] ifFalse:[ |
957
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
855 |
shell := '/bin/sh'. |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
856 |
args := (Array with:'sh' with:'-c' with:aCommand). |
957
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
857 |
]. |
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
858 |
e at:'SHELL' put:shell. |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
859 |
|
914 | 860 |
OperatingSystem |
957
8c167c9ea5c0
also pass WINDOWID (if known) and SHELL in environment.
Claus Gittinger <cg@exept.de>
parents:
955
diff
changeset
|
861 |
exec:shell |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
862 |
withArguments:args |
929 | 863 |
environment:e |
914 | 864 |
fileDescriptors:execFdArray |
865 |
closeDescriptors:#() |
|
866 |
fork:true |
|
992 | 867 |
newPgrp:true |
868 |
inDirectory:aDirectory. |
|
914 | 869 |
] |
870 |
action:[:status | |
|
935 | 871 |
"/ Transcript show:'pid:'; showCR:status pid. |
872 |
"/ Transcript show:'status:'; showCR:status status. |
|
873 |
"/ Transcript show:'code:'; showCR:status code. |
|
874 |
"/ Transcript show:'core:'; showCR:status core. |
|
914 | 875 |
status stillAlive ifFalse:[ |
876 |
exitStatus := status. |
|
877 |
OperatingSystem closePid:shellPid. |
|
878 |
shellPid := nil. |
|
879 |
self pushEvent:#shellTerminated |
|
880 |
]. |
|
881 |
]. |
|
882 |
||
883 |
shellPid isNil ifTrue:[ |
|
884 |
self halt. |
|
885 |
(p at:1) close. |
|
886 |
(p at:2) close. |
|
887 |
]. |
|
888 |
||
889 |
blocked ifFalse:[ |
|
890 |
OperatingSystem unblockInterrupts |
|
891 |
]. |
|
892 |
||
893 |
self startReaderProcess. |
|
894 |
||
992 | 895 |
"Created: / 20.7.1998 / 18:19:32 / cg" |
896 |
"Modified: / 20.7.1998 / 18:30:12 / cg" |
|
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
897 |
! |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
898 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
899 |
startShell |
992 | 900 |
"start a shell on a pseudo terminal in the current directory. |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
901 |
Also fork a reader process, to read the shells output and |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
902 |
tell me, whenever something arrives" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
903 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
904 |
^ self startCommand:nil |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
905 |
|
914 | 906 |
" |
934 | 907 |
VT100TerminalView openShell |
914 | 908 |
" |
929 | 909 |
|
992 | 910 |
"Modified: / 20.7.1998 / 18:29:54 / cg" |
911 |
! |
|
912 |
||
913 |
startShellIn:aDirectory |
|
914 |
"start a shell on a pseudo terminal in some directory. |
|
915 |
Also fork a reader process, to read the shells output and |
|
916 |
tell me, whenever something arrives" |
|
917 |
||
918 |
^ self startCommand:nil in:aDirectory |
|
919 |
||
920 |
" |
|
921 |
VT100TerminalView openShellIn:'/etc' |
|
922 |
" |
|
923 |
||
924 |
"Modified: / 20.7.1998 / 18:29:46 / cg" |
|
914 | 925 |
! ! |
926 |
||
927 |
!TerminalView methodsFor:'menu'! |
|
928 |
||
929 |
editMenu |
|
930 |
"return the views middleButtonMenu" |
|
931 |
||
932 |
<resource: #keyboard (#Copy #Paste #Print)> |
|
933 |
<resource: #programMenu> |
|
934 |
||
935 |
|items m sub shortKeys sensor| |
|
936 |
||
937 |
((sensor := self sensor) notNil and:[sensor ctrlDown]) ifTrue:[ |
|
938 |
items := #( |
|
939 |
('Interrupt' doSendInterrupt) |
|
940 |
). |
|
941 |
] ifFalse:[ |
|
942 |
items := #( |
|
943 |
('copy' copySelection Copy ) |
|
944 |
('paste' pasteOrReplace Paste ) |
|
945 |
('-' ) |
|
951 | 946 |
('font ...' changeFont ) |
947 |
('-' ) |
|
914 | 948 |
('save as ...' save SaveAs ) |
949 |
('print' doPrint Print ) |
|
950 |
). |
|
951 |
]. |
|
952 |
||
953 |
m := PopUpMenu itemList:items resources:resources. |
|
954 |
||
955 |
self hasSelection not ifTrue:[ |
|
956 |
m disable:#copySelection. |
|
957 |
]. |
|
958 |
^ m. |
|
959 |
||
951 | 960 |
"Modified: / 12.6.1998 / 22:33:33 / cg" |
914 | 961 |
! ! |
962 |
||
940 | 963 |
!TerminalView methodsFor:'misc'! |
914 | 964 |
|
965 |
removeTrailingBlankLines |
|
966 |
^ self |
|
967 |
! ! |
|
968 |
||
969 |
!TerminalView methodsFor:'processing - input'! |
|
970 |
||
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
971 |
processInput:buffer n:count |
997 | 972 |
|sensor| |
973 |
||
964
43d6e33a4240
keep cursor off while more input is arriving.
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
974 |
self hideCursor. |
997 | 975 |
|
976 |
access critical:[ |
|
977 |
|i i2 s crnlFollows| |
|
978 |
||
979 |
i := 1. |
|
980 |
[i <= count] whileTrue:[ |
|
981 |
(state == 0) ifTrue:[ |
|
982 |
"/ in initial state. |
|
983 |
"/ quick scan forward for next control character ... |
|
984 |
i2 := buffer indexOfControlCharacterStartingAt:i. |
|
985 |
i2 == 0 ifTrue:[ |
|
986 |
"/ no control characters - simply append all |
|
987 |
"/ to the outstanding lines ... |
|
988 |
s := buffer copyFrom:i to:count. |
|
989 |
i := count + 1. "/ leave loop. |
|
990 |
crnlFollows := false. |
|
991 |
] ifFalse:[ |
|
992 |
i2 > i ifTrue:[ |
|
993 |
s := buffer copyFrom:i to:i2-1. |
|
994 |
i := i2. "/ proceed withcontrol character |
|
995 |
crnlFollows := false. |
|
996 |
i < (count - 1) ifTrue:[ |
|
997 |
(buffer at:i) == Character return ifTrue:[ |
|
998 |
(buffer at:i+1) == Character nl ifTrue:[ |
|
999 |
crnlFollows := true. |
|
1000 |
i := i + 2. |
|
1001 |
] |
|
1002 |
] |
|
1003 |
]. |
|
1004 |
] |
|
1005 |
]. |
|
1006 |
]. |
|
1007 |
||
1008 |
s notNil ifTrue:[ |
|
1009 |
currentEmphasis notNil ifTrue:[ |
|
1010 |
s := s emphasizeAllWith:currentEmphasis |
|
1011 |
]. |
|
1012 |
||
1013 |
outstandingLine size > 0 ifTrue:[ |
|
1014 |
outstandingLine := outstandingLine , s. |
|
1015 |
] ifFalse:[ |
|
1016 |
outstandingLine := s. |
|
1017 |
]. |
|
1018 |
crnlFollows ifTrue:[ |
|
1019 |
outstandingLines isNil ifTrue:[ |
|
1020 |
outstandingLines := OrderedCollection with:outstandingLine |
|
1021 |
] ifFalse:[ |
|
1022 |
outstandingLines add:outstandingLine. |
|
1023 |
]. |
|
1024 |
outstandingLine := ''. |
|
1025 |
]. |
|
1026 |
s := nil. |
|
1027 |
||
1028 |
collecting ifTrue:[ |
|
1029 |
flushPending ifFalse:[ |
|
1030 |
self installDelayedUpdate |
|
1031 |
] ifTrue:[ |
|
1032 |
"/ outstandingLines size > collectSize ifTrue:[ |
|
1033 |
"/ self endEntry |
|
1034 |
"/ ] |
|
1035 |
] |
|
1036 |
] ifFalse:[ |
|
1037 |
self endEntry |
|
1038 |
]. |
|
1039 |
] ifFalse:[ |
|
1040 |
"/ no chunk to append (in an escape sequence) |
|
1041 |
"/ must handle individual characters |
|
1042 |
"/ to update the state machine. |
|
1043 |
self nextPut:(buffer at:i). |
|
1044 |
i := i + 1. |
|
1045 |
] |
|
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
1046 |
]. |
948 | 1047 |
|
997 | 1048 |
]. |
1049 |
||
1050 |
(sensor := self sensor) notNil ifTrue:[ |
|
1051 |
(sensor hasEvent:#processInput:n: for:self) ifFalse:[ |
|
1052 |
self endEntry. |
|
1053 |
self showCursor. |
|
1054 |
"/ self makeCursorVisible. |
|
1055 |
] ifTrue:[ |
|
1056 |
outstandingLines size > collectSize ifTrue:[ |
|
1057 |
self endEntry. |
|
1058 |
self showCursor. |
|
1059 |
"/ self makeCursorVisible. |
|
1060 |
"/ redraw |
|
1061 |
windowGroup notNil ifTrue:[ |
|
1062 |
windowGroup processRealExposeEventsFor:self. |
|
1063 |
] |
|
1064 |
]. |
|
1065 |
] |
|
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
1066 |
]. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
1067 |
|
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
1068 |
"Created: / 10.6.1998 / 17:26:09 / cg" |
997 | 1069 |
"Modified: / 21.7.1998 / 19:30:18 / cg" |
914 | 1070 |
! ! |
1071 |
||
1072 |
!TerminalView methodsFor:'queries'! |
|
1073 |
||
1074 |
preferredExtent |
|
951 | 1075 |
^ (fontWidth * numberOfColumns + (leftMargin * 2)) |
1076 |
@ |
|
979 | 1077 |
((self heightForLines:numberOfLines) + 8) |
926 | 1078 |
|
979 | 1079 |
"Modified: / 20.6.1998 / 20:06:57 / cg" |
929 | 1080 |
! |
1081 |
||
1082 |
terminalType |
|
1083 |
^ #dump |
|
1084 |
||
1085 |
"Modified: / 10.6.1998 / 14:47:03 / cg" |
|
1086 |
"Created: / 10.6.1998 / 16:22:30 / cg" |
|
914 | 1087 |
! ! |
1088 |
||
1089 |
!TerminalView methodsFor:'selection handling'! |
|
1090 |
||
1091 |
paste:someText |
|
1092 |
"paste - redefined to send the chars to the shell instead |
|
1093 |
of pasting into the view" |
|
1094 |
||
950 | 1095 |
|s nLines| |
1096 |
||
1097 |
s := someText. |
|
1098 |
s isString ifTrue:[ |
|
1099 |
s := s asStringCollection |
|
1100 |
] ifFalse:[ |
|
1101 |
(s isKindOf:StringCollection) ifFalse:[ |
|
1102 |
self warn:'selection (' , s class name , ') is not convertable to Text'. |
|
1103 |
^ self |
|
1104 |
] |
|
1105 |
]. |
|
1106 |
(nLines := s size) == 0 ifTrue:[^ self]. |
|
1107 |
(nLines == 1 and:[(s at:1) size == 0]) ifTrue:[^ self]. |
|
1108 |
s keysAndValuesDo:[:idx :line | |
|
1109 |
inStream nextPutAll:line. |
|
1110 |
idx ~~ nLines ifTrue:[ |
|
1111 |
inStream nextPut:(Character return). |
|
1112 |
] |
|
1113 |
]. |
|
1114 |
||
1115 |
"Modified: / 12.6.1998 / 22:12:47 / cg" |
|
914 | 1116 |
! ! |
1117 |
||
1118 |
!TerminalView class methodsFor:'documentation'! |
|
1119 |
||
1120 |
version |
|
1005 | 1121 |
^ '$Header: /cvs/stx/stx/libwidg2/TerminalView.st,v 1.50 1998-07-23 13:05:44 tz Exp $' |
914 | 1122 |
! ! |