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