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