author | Claus Gittinger <cg@exept.de> |
Wed, 04 May 2016 18:55:02 +0200 | |
changeset 5058 | 925bc542ebd1 |
parent 5021 | a24473f2d6ca |
child 5026 | c0ed4e85a203 |
child 5062 | e0a5de3ff115 |
permissions | -rw-r--r-- |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1 |
" |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
2 |
COPYRIGHT (c) 1998 by eXept Software AG |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
3 |
All Rights Reserved |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
4 |
|
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
5 |
This software is furnished under a license and may be used |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
6 |
only in accordance with the terms of that license and with the |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
7 |
inclusion of the above copyright notice. This software may not |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
8 |
be provided or otherwise made available to, or used by, any |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
9 |
other person. No title to or ownership of the software is |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
10 |
hereby transferred. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
11 |
" |
1833 | 12 |
"{ Package: 'stx:libwidg2' }" |
13 |
||
4718 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
914 | 16 |
TextCollector subclass:#TerminalView |
2268 | 17 |
instanceVariableNames:'inStream outStream readerProcess shellPid kbdSequences |
18 |
escapeSequenceTree currentSequence kbdMap escapeLeadingChars |
|
19 |
numberOfColumns numberOfLines shellTerminateAction rangeStartLine |
|
20 |
rangeEndLine state savedCursor shellCommand shellDirectory |
|
4317 | 21 |
filterStream recorderStream localEcho translateNLToCRNL |
4604 | 22 |
inputTranslateCRToNL inputTranslateCRToCRNL |
23 |
inputTranslateBackspaceToDelete autoWrapFlag masterWindow |
|
24 |
alternateKeypadMode noColors sizeOfOutstandingInputToBeProcessed |
|
25 |
lineEditMode lineBuffer lineBufferCursorPosition |
|
4641 | 26 |
lineBufferHistory lineBufferHistoryPosition maxHistorySize doUTF |
4815 | 27 |
ignoreOutput sendControlKeys |
5008 | 28 |
lastSelectedLineBufferHistoryPosition inputIsUTF8 outputIsUTF8 |
29 |
signalControlKeys' |
|
4602 | 30 |
classVariableNames:'Debug DebugKeyboard DefaultMaxHistorySize' |
2268 | 31 |
poolDictionaries:'' |
32 |
category:'Views-TerminalViews' |
|
914 | 33 |
! |
34 |
||
35 |
!TerminalView class methodsFor:'documentation'! |
|
36 |
||
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
37 |
copyright |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
38 |
" |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
39 |
COPYRIGHT (c) 1998 by eXept Software AG |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
40 |
All Rights Reserved |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
41 |
|
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
42 |
This software is furnished under a license and may be used |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
43 |
only in accordance with the terms of that license and with the |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
44 |
inclusion of the above copyright notice. This software may not |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
45 |
be provided or otherwise made available to, or used by, any |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
46 |
other person. No title to or ownership of the software is |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
47 |
hereby transferred. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
48 |
" |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
49 |
|
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
50 |
! |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
51 |
|
914 | 52 |
documentation |
53 |
" |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
54 |
I provide terminal functionality, by interpreting data |
1418 | 55 |
arriving from some stream (typically connected to a command interpreter |
4597 | 56 |
via a pty, or another system via a modem) and sending my keyboard data to it. |
57 |
||
58 |
I am abstract providing general functionality - |
|
59 |
concrete terminal characteristics (i.e. escape sequences) are defined |
|
60 |
by concrete subclasses (see VT52TerminalView, VT100TerminalView). |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
61 |
|
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
62 |
Concrete applications are: |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
63 |
consoles (VT100TerminalView), |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
64 |
telnet-views (see TelnetTool) |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
65 |
editor wrappers (if you like emacs/vi) |
4597 | 66 |
gdb terminal subviews (see GDBApplication) |
914 | 67 |
|
4223 | 68 |
Although my class protocol includes common startup protocol |
1418 | 69 |
(to open a terminalView with a shell or on the output of a command), |
4223 | 70 |
I can be used as a widget within an application (modem software). |
1418 | 71 |
|
4597 | 72 |
Notice, some of my pty functionality and handling ex beeing extracted to |
73 |
the separate TerminalSession class (which allows communicating with a |
|
74 |
program without having its output displayed . |
|
75 |
So currently, some ugly code duplication is present. |
|
76 |
Once stable, code will be refactored. |
|
77 |
For now, as terminalView is being used in |
|
78 |
some of our critical applications, this refactoring has not yet been done. |
|
79 |
||
914 | 80 |
[author:] |
81 |
Claus Gittinger |
|
915 | 82 |
|
1341
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
83 |
[instance variables:] |
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
84 |
inStream stream where keyboard input is |
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
85 |
sent to (connected to shells or commands input) |
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
86 |
|
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
87 |
outStream stream where the output of the |
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
88 |
shell or command arrives |
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
89 |
(read here and displayed in the view) |
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
90 |
|
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
91 |
readerProcess process which reads commands |
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
92 |
output and sends it to the view |
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
93 |
|
4598 | 94 |
lineEditMode if on, do readLine-alike input history and editong |
95 |
||
5008 | 96 |
signalControlKeys if on, CTRL-C sends an interrupt (for Windows) |
97 |
||
2204 | 98 |
[class variables]: |
99 |
Debug := true trace incoming characters |
|
5008 | 100 |
Debug := false |
101 |
DebugKeyboard := true trace outgoing characters |
|
102 |
DebugKeyboard := false |
|
2204 | 103 |
|
104 |
||
915 | 105 |
[start with:] |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
106 |
VT52TerminalView open |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
107 |
VT100TerminalView open |
915 | 108 |
VT52TerminalView openShell |
919 | 109 |
VT100TerminalView openShell |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
110 |
VT100TerminalView openOnCommand:'ls -l' |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
111 |
VT100TerminalView openOnCommand:'dir' |
1418 | 112 |
|
113 |
[see also:] |
|
114 |
TelNetTool |
|
914 | 115 |
" |
3758 | 116 |
! |
117 |
||
118 |
example |
|
119 |
" |
|
120 |
|terminal in out inputLine| |
|
121 |
||
122 |
in := InternalPipeStream new. |
|
123 |
out := InternalPipeStream new. |
|
124 |
||
125 |
terminal := TerminalView openOnInput:in output:out. |
|
126 |
terminal localEcho:true. |
|
127 |
terminal inputTranslateCRToNL:true. |
|
128 |
||
129 |
out nextPutLine:'Hello world - please type at me:'. |
|
130 |
||
131 |
[ |
|
132 |
inputLine := in nextLine asString. |
|
133 |
inputLine ~= '#exit' ifTrue:[ |
|
134 |
out nextPutLine:(Compiler evaluate:inputLine) printString. |
|
135 |
]. |
|
136 |
inputLine = '#exit' |
|
137 |
] whileFalse. |
|
138 |
||
139 |
terminal topView destroy. |
|
140 |
" |
|
914 | 141 |
! ! |
142 |
||
2207 | 143 |
!TerminalView class methodsFor:'initialization'! |
2205 | 144 |
|
145 |
initialize |
|
2207 | 146 |
|
4294 | 147 |
Debug := DebugKeyboard := false. |
4602 | 148 |
DefaultMaxHistorySize := 1000. |
2207 | 149 |
|
4294 | 150 |
" |
151 |
self initialize |
|
152 |
" |
|
2205 | 153 |
! ! |
154 |
||
1052 | 155 |
!TerminalView class methodsFor:'defaults'! |
156 |
||
157 |
defaultIcon |
|
4030 | 158 |
"This resource specification was automatically generated |
159 |
by the ImageEditor of ST/X." |
|
160 |
||
161 |
"Do not manually edit this!! If it is corrupted, |
|
162 |
the ImageEditor may not be able to read the specification." |
|
163 |
||
164 |
" |
|
165 |
self defaultIcon inspect |
|
166 |
ImageEditor openOnClass:self andSelector:#defaultIcon |
|
167 |
Icon flushCachedIcons |
|
168 |
" |
|
169 |
||
170 |
<resource: #image> |
|
4028 | 171 |
|
4030 | 172 |
^Icon |
4725 | 173 |
constantNamed:'TerminalView defaultIcon' |
174 |
ifAbsentPut:[(Depth4Image new) width:48; height:36; bits:(ByteArray fromPackedString:' |
|
175 |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@CL3L3L3L3L3L3L3L3L0@@@@@@@@@@@@@5UUUUUUUUUUUUUUUUUS@@@@@@@@@@@@MUUUUUUUUUUUUUUUUUUU |
|
176 |
DP@@@@@@@@@@MUQDQDQDQDQDQDQDQEUUDP@@@@@@@@@@MUQDQDQDQDQDQDQDQDUUDQ@@@@@@@@@@MUQBIBQBP"H$P$QDQDUUDQ@@@@@@@@@@MUQDQDQDQDQD |
|
177 |
QDQDQDUUDQD@@@@@@@@@MUQBH"P"P"IDQDQDQDUUDQD@@@@@@@@@MUQDQDQDQDQDQDQDQDUUDQDP@@@@@@@@MUQBH"H"H"P"H"QDQDUUDQDP@@@@@@@@MUQD |
|
178 |
QDQDQDQDQDQDQDUUDQDP@@@@@@@@MUQBH$H"IBIDH"QDQDUUDQDP@@@@@@@@MUQDQDQDQDQDQDQDQDUUDQDP@@@@@@@@MUQBQDQDQDQDQDQDQDUUDQDP@@@@ |
|
179 |
@@@@MUQDQDQDQDQDQDQDQDUUDQDP@@@@@@@@MUQBH"P$H"P$QDQDQDUUDQDP@@@@@@@@MUQDQDQDQDQDQDQDQDUUDQDP@@@@@@@@MUQBP"H$QDQDQDQDQDUU |
|
180 |
DQDP@@@@@@@@MUUDQDQDQDQDQDQDQEUUDQD@@@@@@@@@MUUUUUUUUUUUUUUUUUUUDQ@@@@@@@@@@@5UUUUUUUUUUUUUUUUUQDP@@@@@@@@@@@@@QDQDQDQDQ |
|
181 |
DQDQDQDSL1D@@@@@@@@@@@@CL3L3L3L3L3L3L3L3LQD@@@@@@@@@@@@QDQDQDQDQDQDQDQDQDQD@@@@@@@@@@AUUUUUUUUUUUUUUUUUUDQD3@3@@@@@@@AUU |
|
182 |
UUUUUUUUUU@@@@AUDQD@L@L@@@@@DQDQDQDQDQDQDQDQDQUUDQ@@@C@@@@@AUUUUUUUUUUUUUUUUUQDQD@@@@0@@@@@UUUUUUUUUUUUUUUUUTQ@@@@DQDQ@@ |
|
183 |
@@@UT"H"H"H"H"H"H%UUTQ@@DQDSL1@@@@EUUUUUUUUUUUUUUUUUDP@AEUTQL1@@@AURH"H"H"H"H"H"IUUQD@@AUUUSLP@@@UUUUUUUUUUUUUUUUUTQ@@@A |
|
184 |
L3L1D@@@@QDQDQDQDQDQDQDQDQDP@@@ADQDQ@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@') ; colorMapFromArray:#[0 0 0 80 78 80 255 255 255 140 140 140 40 58 10 196 194 190]; mask:((ImageMask new) width:48; height:36; bits:(ByteArray fromPackedString:' |
|
4030 | 185 |
@@@@@@@@@O???>@@@_????@@@?????0@@?????0@@?????8@@?????8@@?????<@@?????<@@?????>@@?????>@@?????>@@?????>@@?????>@@?????>@ |
186 |
@?????>@@?????>@@?????>@@?????>@@?????<@@?????8@@_????0@@C????<@@A????<@@C????<@@O?????X@O????<$@?????8HA????? PC????8G8 |
|
187 |
C????8?8G????1?8O????!!?0_????A? _???>A?@@@@@@@@@') ; yourself); yourself] |
|
1317
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
188 |
! |
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
189 |
|
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
190 |
defaultNumberOfColumns |
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
191 |
^ 80 |
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
192 |
|
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
193 |
"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
|
194 |
"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
|
195 |
! |
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
196 |
|
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
197 |
defaultNumberOfLines |
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
198 |
^ 25 |
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
199 |
|
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
200 |
"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
|
201 |
"Modified: / 4.8.1998 / 17:48:31 / cg" |
1052 | 202 |
! ! |
203 |
||
972 | 204 |
!TerminalView class methodsFor:'opening'! |
914 | 205 |
|
928 | 206 |
open |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
207 |
^ self openShell |
928 | 208 |
|
209 |
" |
|
210 |
VT100TerminalView open |
|
4446
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
211 |
VT52TerminalView open |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
212 |
TerminalView open |
928 | 213 |
" |
214 |
||
215 |
"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
|
216 |
"Modified: / 9.7.1998 / 17:55:37 / cg" |
928 | 217 |
! |
218 |
||
914 | 219 |
openDummy |
972 | 220 |
"for testing purposes only - opens a dummy tty-view, which simply |
221 |
echoes whatever is typed in" |
|
222 |
||
914 | 223 |
|in vt52| |
224 |
||
225 |
vt52 := self new. |
|
226 |
in := ForwardingStream on:''. |
|
227 |
||
228 |
in fwdStream:vt52. |
|
229 |
vt52 inStream:in. |
|
230 |
vt52 outStream:in. |
|
231 |
vt52 open |
|
232 |
||
233 |
" |
|
234 |
self openDummy |
|
235 |
" |
|
236 |
! |
|
237 |
||
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
238 |
openOnCommand:aCommandString |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
239 |
"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
|
240 |
(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
|
241 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
242 |
^ self openOnCommand:aCommandString onExit:[] |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
243 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
244 |
" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
245 |
VT100TerminalView openOnCommand:'ls -l' |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
246 |
" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
247 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
248 |
"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
|
249 |
"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
|
250 |
! |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
251 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
252 |
openOnCommand:aCommandString onExit:aBlock |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
253 |
"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
|
254 |
(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
|
255 |
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
|
256 |
|
4254 | 257 |
|top scr vt| |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
258 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
259 |
top := StandardSystemView new. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
260 |
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
|
261 |
scr origin:0.0@0.0 corner:1.0@1.0. |
4220 | 262 |
vt := scr scrolledView. |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
263 |
|
4220 | 264 |
vt masterWindow: top. |
265 |
vt startCommand:aCommandString. |
|
266 |
vt shellTerminateAction:[ |
|
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
267 |
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
|
268 |
]. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
269 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
270 |
top extent:(scr preferredExtent). |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
271 |
top label:('executing: "' , aCommandString , '"'). |
1014 | 272 |
top iconLabel:'command'. |
1052 | 273 |
top icon:(self defaultIcon). |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
274 |
top open. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
275 |
|
4220 | 276 |
^ vt |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
277 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
278 |
" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
279 |
VT100TerminalView openOnCommand:'ls -lR' |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
280 |
VT100TerminalView openOnCommand:'vi /etc/hosts' |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
281 |
" |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
282 |
|
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
283 |
"Created: / 9.7.1998 / 17:54:34 / cg" |
1052 | 284 |
"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
|
285 |
! |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
286 |
|
1014 | 287 |
openOnInput:inStream output:outStream |
972 | 288 |
"open a terminalView on the given streams (which are typically some |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
289 |
kind of socket or pty). |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
290 |
Keys pressed are sent to inStream, text appearing |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
291 |
from outStream is displayed in the terminal view. |
972 | 292 |
This can be used to implement things like rlogin |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
293 |
or telnet views (if connected to a modem, a com-program can also be |
972 | 294 |
implemented this way)." |
295 |
||
4268 | 296 |
|top vt| |
972 | 297 |
|
298 |
top := StandardSystemView new. |
|
4268 | 299 |
vt := self openOnInput:inStream output:outStream in:top. |
300 |
vt masterWindow:top. |
|
2078 | 301 |
|
4268 | 302 |
top extent:(vt preferredExtent). |
2078 | 303 |
top label:'shell'. |
304 |
top iconLabel:'shell'. |
|
305 |
top icon:(self defaultIcon). |
|
306 |
top open. |
|
4268 | 307 |
^ vt |
2078 | 308 |
|
309 |
"Modified: / 5.5.1999 / 17:25:59 / cg" |
|
310 |
! |
|
311 |
||
312 |
openOnInput:inStream output:outStream in:aView |
|
2778 | 313 |
"open a terminalView on the given streams |
314 |
(which are typically some kind of socket or pty). |
|
2078 | 315 |
Keys pressed are sent to inStream, text appearing |
316 |
from outStream is displayed in the terminal view. |
|
317 |
This can be used to implement things like rlogin |
|
318 |
or telnet views (if connected to a modem, a com-program can also be |
|
319 |
implemented this way)." |
|
320 |
||
321 |
|scr vt| |
|
322 |
||
323 |
scr := ScrollableView for:self in:aView. |
|
972 | 324 |
scr origin:0.0@0.0 corner:1.0@1.0. |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
325 |
vt := scr scrolledView. |
972 | 326 |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
327 |
vt inStream:inStream. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
328 |
vt outStream:outStream. |
2778 | 329 |
vt startReaderProcessWhenVisible. |
972 | 330 |
|
2078 | 331 |
^ scr |
974 | 332 |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
333 |
"Modified: / 5.5.1999 / 17:25:59 / cg" |
972 | 334 |
! |
335 |
||
914 | 336 |
openShell |
972 | 337 |
"start a shell on a pseudo-TTY, open a terminalView on it |
338 |
(i.e. this is kind of an xterm)" |
|
339 |
||
997 | 340 |
^ self openShellIn:nil |
992 | 341 |
|
342 |
" |
|
343 |
VT100TerminalView openShell |
|
344 |
" |
|
345 |
||
997 | 346 |
"Modified: / 21.7.1998 / 18:24:55 / cg" |
992 | 347 |
! |
348 |
||
349 |
openShellIn:aDirectory |
|
350 |
"start a shell on a pseudo-TTY, open a terminalView on it |
|
351 |
(i.e. this is kind of an xterm)" |
|
352 |
||
2163 | 353 |
| top scr vt lbl| |
914 | 354 |
|
355 |
top := StandardSystemView new. |
|
4446
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
356 |
scr := HVScrollableView for:self in:top. |
914 | 357 |
scr origin:0.0@0.0 corner:1.0@1.0. |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
358 |
vt := scr scrolledView. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
359 |
vt startShellIn:aDirectory. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
360 |
vt shellTerminateAction:[top destroy]. |
4220 | 361 |
vt masterWindow: top. |
914 | 362 |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
363 |
lbl := OperatingSystem isUNIXlike ifTrue:['shell'] ifFalse:['dos']. |
940 | 364 |
top extent:(scr preferredExtent). |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
365 |
top label:lbl. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
366 |
top iconLabel:lbl. |
1052 | 367 |
top icon:(self defaultIcon). |
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
368 |
top open. |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
369 |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
370 |
^ vt |
914 | 371 |
|
372 |
" |
|
4446
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
373 |
TerminalView openShellIn:'/etc' |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
374 |
VT52TerminalView openShellIn:'/etc' |
992 | 375 |
VT100TerminalView openShellIn:'/etc' |
914 | 376 |
" |
946 | 377 |
|
992 | 378 |
"Created: / 20.7.1998 / 18:28:15 / cg" |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
379 |
"Modified: / 5.5.1999 / 17:27:10 / cg" |
914 | 380 |
! ! |
381 |
||
972 | 382 |
!TerminalView class methodsFor:'queries'! |
383 |
||
384 |
isVisualStartable |
|
385 |
"returns whether this application class can be started via #open" |
|
386 |
||
387 |
self == TerminalView ifTrue:[^ false]. |
|
388 |
^ true |
|
389 |
||
390 |
"Created: / 10.6.1998 / 15:48:43 / cg" |
|
391 |
! ! |
|
392 |
||
914 | 393 |
!TerminalView methodsFor:'accessing'! |
394 |
||
4897 | 395 |
filterStream |
396 |
"get a filter stream if any; if not nil, it gets all incoming data via nextPutAll:. |
|
397 |
Added to allow saving incoming data to a file, but can also be used to catch/filter/lookAt |
|
398 |
incoming data by some other program" |
|
399 |
||
400 |
^ filterStream |
|
401 |
! |
|
402 |
||
403 |
filterStream:aStream |
|
2076 | 404 |
"set a filter stream; if not nil, it gets all incoming data via nextPutAll:. |
4317 | 405 |
Added to allow saving incoming data to a file, but can also be used to catch/filter/lookAt |
406 |
incoming data by some other program" |
|
2076 | 407 |
|
4897 | 408 |
filterStream := aStream. |
2076 | 409 |
|
410 |
"Created: / 28.1.2002 / 20:56:04 / micha" |
|
411 |
"Modified: / 28.1.2002 / 20:56:11 / micha" |
|
412 |
! |
|
413 |
||
914 | 414 |
inStream |
2954 | 415 |
"set the stream, which gets all input data (i.e. keyboard input)" |
914 | 416 |
|
2075 | 417 |
^ inStream |
418 |
! |
|
914 | 419 |
|
420 |
inStream:something |
|
2954 | 421 |
"return the stream, which gets all input data (i.e. keyboard input)" |
914 | 422 |
|
2075 | 423 |
inStream := something. |
424 |
! |
|
914 | 425 |
|
4639 | 426 |
lineBufferHistory |
427 |
^ lineBufferHistory |
|
428 |
! |
|
429 |
||
430 |
lineBufferHistory:aCollection |
|
4799 | 431 |
aCollection isNil ifTrue:[ |
432 |
lineBufferHistory := OrderedCollection new. |
|
433 |
] ifFalse:[ |
|
434 |
lineBufferHistory := OrderedCollection withAll:aCollection. |
|
435 |
]. |
|
4640 | 436 |
lineBufferHistoryPosition := lineBufferHistory size + 1. |
4639 | 437 |
! |
438 |
||
4803 | 439 |
masterWindow:aTopView |
440 |
"if set, and a corresponding osCommand escape sequence is received, |
|
441 |
that topView's title, icon or other attribute is changed. |
|
442 |
Needed to support xterm's 'set window title' escape sequence" |
|
443 |
||
444 |
masterWindow := aTopView. |
|
4299 | 445 |
! |
446 |
||
914 | 447 |
outStream |
2954 | 448 |
"return the stream, which is used to present data in the view (i.e. shell output)" |
914 | 449 |
|
2075 | 450 |
^ outStream |
451 |
! |
|
914 | 452 |
|
453 |
outStream:something |
|
2954 | 454 |
"set the stream, which is used to present data in the view (i.e. shell output)" |
914 | 455 |
|
2075 | 456 |
outStream := something. |
457 |
! |
|
946 | 458 |
|
1004 | 459 |
readerProcess |
460 |
^ readerProcess |
|
461 |
! |
|
462 |
||
4317 | 463 |
recorderStream:aWriteStream |
464 |
"set a recorder stream; if not nil, it gets all user input (keyboard) data via nextPut:. |
|
4803 | 465 |
Allows saving of user input to a file, for later replay of a session" |
4317 | 466 |
|
467 |
recorderStream := aWriteStream. |
|
468 |
! |
|
469 |
||
4803 | 470 |
shellDirectory:aPathname |
471 |
"the directory, in which the shell/command should be executed. |
|
472 |
By default, the 'current' directory is used" |
|
473 |
||
474 |
shellDirectory := aPathname. |
|
4630 | 475 |
! |
476 |
||
946 | 477 |
shellTerminateAction:aBlock |
478 |
"set the block which is evaluated when the shell terminates. |
|
4803 | 479 |
Can be used to close down the application or perform any other cleanup action." |
946 | 480 |
|
481 |
shellTerminateAction := aBlock. |
|
482 |
||
483 |
"Created: / 12.6.1998 / 17:02:58 / cg" |
|
4803 | 484 |
! ! |
485 |
||
486 |
!TerminalView methodsFor:'accessing - behavior'! |
|
487 |
||
488 |
inputTranslateBackspaceToDelete |
|
489 |
^ inputTranslateBackspaceToDelete |
|
490 |
! |
|
491 |
||
492 |
inputTranslateBackspaceToDelete:aBoolean |
|
493 |
inputTranslateBackspaceToDelete := aBoolean. |
|
494 |
! |
|
495 |
||
496 |
inputTranslateCRToNL |
|
497 |
^ inputTranslateCRToNL |
|
498 |
! |
|
499 |
||
500 |
inputTranslateCRToNL:aBoolean |
|
501 |
inputTranslateCRToNL := aBoolean. |
|
502 |
! |
|
503 |
||
504 |
lineEditMode:something |
|
505 |
lineEditMode := something. |
|
506 |
! |
|
507 |
||
508 |
localEcho:aBoolean |
|
509 |
"enable/disable local echo" |
|
510 |
||
511 |
localEcho := aBoolean |
|
512 |
||
513 |
"Created: / 5.5.1999 / 17:53:16 / cg" |
|
514 |
! |
|
515 |
||
516 |
noColors |
|
517 |
"the noColors boolean disables color changes (from color rendition escape sequences)" |
|
518 |
||
519 |
^ noColors |
|
520 |
! |
|
521 |
||
522 |
noColors:aBoolean |
|
523 |
"the noColors boolean disables color changes (from color rendition escape sequences)" |
|
524 |
||
525 |
noColors := aBoolean. |
|
526 |
! |
|
527 |
||
528 |
sendControlKeys |
|
529 |
"there is some conflict with control key handling, for keys such as CTRL-c: |
|
530 |
it is both a shortcut (eg. Copy) and sometimes required in the terminal (interrupt key). |
|
531 |
For this, we look if there is a current selection, and if so, always treat it as a |
|
532 |
shortcut (and NOT sending it to the terminal's program). |
|
533 |
Otherwise, if there is no selection, look at the 'sendControlKeys' boolean. |
|
534 |
If it is set (which is the default), then send it to the terminal, otherwise perform the editor op. |
|
535 |
Thus, an application containing me can offer a menu function (or toggle), |
|
536 |
to control this behavior on the UI level." |
|
537 |
||
538 |
^ sendControlKeys |
|
539 |
! |
|
540 |
||
541 |
sendControlKeys:aBoolean |
|
542 |
"there is some conflict with control key handling, for keys such as CTRL-c: |
|
543 |
it is both a shortcut (eg. Copy) and sometimes required in the terminal (interrupt key). |
|
544 |
For this, we look if there is a current selection, and if so, always treat it as a |
|
545 |
shortcut (and NOT sending it to the terminal's program). |
|
546 |
Otherwise, if there is no selection, look at the 'sendControlKeys' boolean. |
|
547 |
If it is set (which is the default), then send it to the terminal, otherwise perform the editor op. |
|
548 |
Thus, an application containing me can offer a menu function (or toggle), |
|
549 |
to control this behavior on the UI level." |
|
550 |
||
551 |
sendControlKeys := aBoolean |
|
2076 | 552 |
! |
553 |
||
5008 | 554 |
signalControlKeys |
555 |
"if true (default on Windows), CTRL-C sends an interrupt to |
|
556 |
the program. Otherwise, it is sent as a character (0x03)" |
|
557 |
||
558 |
^ signalControlKeys |
|
559 |
! |
|
560 |
||
561 |
signalControlKeys:aBoolean |
|
562 |
"if true (default on Windows), CTRL-C sends an interrupt to |
|
563 |
the program. Otherwise, it is sent as a character (0x03)" |
|
564 |
||
565 |
signalControlKeys := aBoolean |
|
566 |
! |
|
567 |
||
2076 | 568 |
translateNLToCRNL |
569 |
^ translateNLToCRNL |
|
570 |
||
571 |
"Created: / 28.1.2002 / 20:32:10 / micha" |
|
572 |
! |
|
573 |
||
4266 | 574 |
translateNLToCRNL:aBoolean |
575 |
translateNLToCRNL := aBoolean. |
|
2076 | 576 |
|
577 |
"Created: / 28.1.2002 / 20:32:10 / micha" |
|
946 | 578 |
! ! |
914 | 579 |
|
580 |
!TerminalView methodsFor:'cursor handling'! |
|
581 |
||
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
582 |
cursorDown:n |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
583 |
cursorLine + n > list size ifTrue:[ |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
584 |
list := list , (Array new:n). |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
585 |
self textChanged. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
586 |
]. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
587 |
super cursorDown:n |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
588 |
|
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
589 |
"Modified: / 10.6.1998 / 17:18:41 / cg" |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
590 |
"Created: / 10.6.1998 / 17:18:50 / cg" |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
591 |
! |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
592 |
|
968
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
593 |
cursorMovementAllowed |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
594 |
"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
|
595 |
(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
|
596 |
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
|
597 |
cursor positioning escape sequences arriving from the |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
598 |
stream." |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
599 |
|
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
600 |
^ false |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
601 |
|
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
602 |
"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
|
603 |
! |
1cb313e6635b
do not allow cursor movement (via buttonPress).
Claus Gittinger <cg@exept.de>
parents:
964
diff
changeset
|
604 |
|
2169 | 605 |
numberOfTerminalCols |
606 |
^ numberOfColumns |
|
607 |
! |
|
608 |
||
1354
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
609 |
numberOfTerminalColumns |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
610 |
^ numberOfColumns |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
611 |
|
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
612 |
"Created: / 5.5.1999 / 11:46:25 / cg" |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
613 |
! |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
614 |
|
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
615 |
numberOfTerminalLines |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
616 |
"/ be careful - this is NOT called numberOfLines, |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
617 |
"/ since that would interfere with numberOfLines as defined |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
618 |
"/ in ListView ... |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
619 |
"/ ... one of the bad sides of subclassing |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
620 |
|
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
621 |
^ numberOfLines |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
622 |
|
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
623 |
"Created: / 5.5.1999 / 11:46:18 / cg" |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
624 |
"Modified: / 5.5.1999 / 11:47:24 / cg" |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
625 |
! |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
626 |
|
1077
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
627 |
restoreCursor |
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
628 |
|l c| |
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
629 |
|
2192 | 630 |
savedCursor isNil ifTrue:[ |
631 |
l := c := 1. |
|
632 |
] ifFalse:[ |
|
633 |
l := savedCursor y. |
|
634 |
c := savedCursor x. |
|
635 |
]. |
|
1077
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
636 |
self cursorLine:l col:c. |
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
637 |
|
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
638 |
"Created: / 14.8.1998 / 13:49:24 / cg" |
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
639 |
! |
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
640 |
|
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
641 |
saveCursor |
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
642 |
savedCursor := cursorCol @ cursorLine |
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
643 |
|
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
644 |
"Created: / 14.8.1998 / 13:48:45 / cg" |
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
645 |
"Modified: / 14.8.1998 / 13:49:32 / cg" |
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
646 |
! |
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
647 |
|
914 | 648 |
validateCursorCol:col inLine:line |
649 |
"check of col is a valid cursor position; return a new col-nr if not. |
|
650 |
Here, the linelength is enforced" |
|
651 |
||
2268 | 652 |
col > numberOfColumns ifTrue:[ |
653 |
autoWrapFlag ifTrue:[ |
|
654 |
self endEntry. |
|
4452 | 655 |
self cursorLine:(self cursorLine + 1) col:1 " (col-numberOfColumns) ". |
2268 | 656 |
^ 1. |
657 |
]. |
|
658 |
]. |
|
926 | 659 |
^ col min:numberOfColumns |
914 | 660 |
|
926 | 661 |
"Modified: / 10.6.1998 / 15:09:41 / cg" |
914 | 662 |
! ! |
663 |
||
1358
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
664 |
!TerminalView methodsFor:'defaults'! |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
665 |
|
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
666 |
anyKeyCodes |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
667 |
^ IdentityDictionary withKeysAndValues: |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
668 |
#( |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
669 |
#Escape '\e' |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
670 |
#BackSpace '\b' |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
671 |
#Return '\r' |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
672 |
#Delete '\0177' |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
673 |
#Tab '\t' |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
674 |
) |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
675 |
|
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
676 |
"Created: / 5.5.1999 / 15:00:37 / cg" |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
677 |
! ! |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
678 |
|
914 | 679 |
!TerminalView methodsFor:'event handling'! |
680 |
||
951 | 681 |
computeNumberOfLinesShown |
682 |
|prevNLines prevNCols| |
|
683 |
||
4518 | 684 |
prevNCols := (innerWidth // gc font width). |
951 | 685 |
prevNLines := nFullLinesShown. |
686 |
||
687 |
super computeNumberOfLinesShown. |
|
688 |
||
4518 | 689 |
((innerWidth // gc font width) ~~ prevNCols |
951 | 690 |
or:[prevNLines ~~ nFullLinesShown]) ifTrue:[ |
691 |
self defineWindowSize. |
|
692 |
] |
|
693 |
||
694 |
"Created: / 12.6.1998 / 22:34:39 / cg" |
|
979 | 695 |
"Modified: / 20.6.1998 / 19:45:28 / cg" |
951 | 696 |
! |
697 |
||
1359 | 698 |
contentsChanged |
4256 | 699 |
"this one is sent, whenever contents changes its size" |
700 |
||
1359 | 701 |
super contentsChanged. |
2594 | 702 |
"/ self defineWindowSize. |
1359 | 703 |
|
704 |
"Modified: / 11.6.1998 / 22:51:48 / cg" |
|
705 |
"Created: / 5.5.1999 / 16:30:15 / cg" |
|
706 |
! |
|
707 |
||
943 | 708 |
defineWindowSize |
2192 | 709 |
| delta prevNumCols prevNumLines| |
1359 | 710 |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
711 |
"/self halt. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
712 |
"/self realized ifFalse:[ |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
713 |
"/ "/ iconfified |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
714 |
"/ ^ self |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
715 |
"/]. |
4518 | 716 |
numberOfColumns := (innerWidth // gc font width). |
1354
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
717 |
delta := numberOfLines - rangeEndLine. |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
718 |
numberOfLines := nFullLinesShown. |
1359 | 719 |
((prevNumCols == numberOfColumns) |
720 |
and:[prevNumLines == numberOfLines]) ifTrue:[ |
|
721 |
^ self |
|
722 |
]. |
|
723 |
||
1354
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
724 |
rangeEndLine notNil ifTrue:[ |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
725 |
rangeEndLine := numberOfLines - delta. |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
726 |
]. |
1341
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
727 |
|
1359 | 728 |
"/ any idea, how to do this under windows ? |
729 |
||
1354
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
730 |
OperatingSystem isUNIXlike ifTrue:[ |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
731 |
"/ |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
732 |
"/ tell the pty; |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
733 |
"/ tell the shell; |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
734 |
"/ |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
735 |
(inStream notNil |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
736 |
and:[inStream isExternalStream |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
737 |
and:[inStream isOpen]]) ifTrue:[ |
4285 | 738 |
Debug ifTrue:[ |
4287 | 739 |
Transcript showCR:'VT100: windowSize changed nLines to ', numberOfLines printString. |
4285 | 740 |
]. |
1354
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
741 |
(OperatingSystem |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
742 |
setWindowSizeOnFileDescriptor:inStream fileDescriptor |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
743 |
width:numberOfColumns |
4285 | 744 |
height:numberOfLines |
745 |
) ifFalse:[ |
|
2192 | 746 |
Debug ifTrue:[ |
747 |
Transcript showCR:'VT100: cannot change windowSize'. |
|
748 |
]. |
|
1354
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
749 |
]. |
964
43d6e33a4240
keep cursor off while more input is arriving.
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
750 |
]. |
1354
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
751 |
shellPid notNil ifTrue:[ |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
752 |
OperatingSystem sendSignal:OperatingSystem sigWINCH to:shellPid |
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
753 |
] |
943 | 754 |
]. |
755 |
||
4655 | 756 |
prevNumCols := numberOfColumns. |
757 |
prevNumLines := numberOfLines. |
|
758 |
||
759 |
"Created: / 11-06-1998 / 22:51:39 / cg" |
|
760 |
"Modified: / 17-07-2014 / 19:40:45 / cg" |
|
943 | 761 |
! |
762 |
||
914 | 763 |
keyPress:aKey x:x y:y |
4164 | 764 |
<resource: #keyboard (#Control #Control_L #Control_R |
765 |
#Shift #Shift_L #Shift_R |
|
766 |
#Alt #Alt_L #Alt_R |
|
767 |
#Cmd #Cmd_L #Cmd_R |
|
768 |
#Meta #Meta_L #Meta_R |
|
769 |
#Return)> |
|
770 |
||
4803 | 771 |
|rest event rawKey seq shortCut| |
1358
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
772 |
|
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
773 |
"/ somewhat complicated, since some characters |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
774 |
"/ should go untranslated (CTRL-key), |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
775 |
"/ even if defined as function keys. |
914 | 776 |
|
777 |
inStream isNil ifTrue:[^ self]. |
|
778 |
||
4294 | 779 |
DebugKeyboard ifTrue:[ |
2192 | 780 |
Transcript showCR:'----'; show:'keyPress:' ; showCR:aKey printString. |
781 |
]. |
|
4601 | 782 |
self shouldProcessInputInLineEditMode ifTrue:[ |
783 |
(self keyPressInLineEditMode:aKey) ifTrue:[^ self]. |
|
4593 | 784 |
]. |
914 | 785 |
|
786 |
aKey isCharacter ifTrue:[ |
|
2466 | 787 |
self deselect. |
788 |
||
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
789 |
localEcho ifTrue:[ |
3758 | 790 |
self nextPut:aKey. |
791 |
self flush. |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
792 |
]. |
4290 | 793 |
"/ send it down to inStream ... |
4317 | 794 |
self sendCharacter:aKey. |
914 | 795 |
^ self |
796 |
]. |
|
797 |
||
1366 | 798 |
(#(Control Control_L Control_R |
799 |
Shift Shift_L Shift_R |
|
800 |
Alt Alt_L Alt_R |
|
801 |
Cmd Cmd_L Cmd_R |
|
802 |
Meta Meta_L Meta_R) includes:aKey) ifTrue:[ |
|
803 |
^ self |
|
804 |
]. |
|
805 |
||
1358
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
806 |
"/ |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
807 |
"/ common translations (Tab, Backspace, F-keys etc.) |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
808 |
"/ |
2078 | 809 |
(aKey == #Return |
810 |
and:[inputTranslateCRToNL]) ifTrue:[ |
|
811 |
seq := '\n'. |
|
812 |
] ifFalse:[ |
|
4324 | 813 |
(aKey == #BackSpace |
814 |
and:[inputTranslateBackspaceToDelete]) ifTrue:[ |
|
815 |
seq := kbdSequences at:#Delete ifAbsent:[ kbdSequences at:aKey ifAbsent:nil ]. |
|
816 |
] ifFalse:[ |
|
817 |
seq := kbdSequences at:aKey ifAbsent:nil. |
|
818 |
]. |
|
2078 | 819 |
]. |
3758 | 820 |
|
914 | 821 |
seq notNil ifTrue:[ |
4294 | 822 |
DebugKeyboard ifTrue:[ |
2192 | 823 |
Transcript show:'->' ; showCR:seq storeString. |
824 |
]. |
|
4105 | 825 |
seq := seq withoutCEscapes. |
2078 | 826 |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
827 |
localEcho ifTrue:[ |
3758 | 828 |
seq do:[:k | self nextPut:k]. |
829 |
self flush. |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
830 |
]. |
4317 | 831 |
self send:seq. |
914 | 832 |
^ self |
833 |
]. |
|
834 |
||
1358
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
835 |
self sensor ctrlDown ifTrue:[ |
1366 | 836 |
(aKey startsWith:'Ctrl') ifTrue:[ |
837 |
rawKey := aKey |
|
838 |
] ifFalse:[ |
|
839 |
"/ already translated - undo it. |
|
840 |
||
841 |
event := WindowGroup lastEventQuerySignal query. |
|
842 |
rawKey := event rawKey. |
|
843 |
rawKey isCharacter ifTrue:[ |
|
844 |
rawKey := 'Ctrl' , rawKey. |
|
845 |
] |
|
1360 | 846 |
] |
1358
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
847 |
] ifFalse:[ |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
848 |
rawKey := self keyboardMap keyAtValue:aKey ifAbsent:aKey. |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
849 |
]. |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
850 |
|
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
851 |
"/ |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
852 |
"/ care for function-keys, which are mapped to Ctrl-x; |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
853 |
"/ |
4294 | 854 |
DebugKeyboard ifTrue:[ |
2192 | 855 |
Transcript show:'raw ->' ; showCR:rawKey storeString. |
856 |
]. |
|
4803 | 857 |
|
858 |
"/ there is some conflict here, for keys such as CTRL-c: |
|
859 |
"/ it is both a shortcut (eg. Copy) and sometimes required in the terminal (interrupt key). |
|
860 |
"/ For this, we look if there is a current selection, and if so, always treat it as a |
|
861 |
"/ shortcut (and NOT sending it to the terminal's program). |
|
862 |
"/ Otherwise, if there is no selection, look at the "sendControlKeys" boolean. |
|
863 |
"/ If it is set (which is the default), then send it to the terminal, otherwise perform the editor op. |
|
864 |
"/ Thus, an application containing me can offer a menu function (or toggle), to control this behavior |
|
865 |
"/ on the UI level. |
|
866 |
||
5006 | 867 |
shortCut := device keyboardMap at:aKey ifAbsent:nil. |
4803 | 868 |
(shortCut notNil and:[shortCut isSymbol]) ifTrue:[ |
4811 | 869 |
(sendControlKeys not or:[ self hasSelection or:[ shortCut == #Paste] ]) ifTrue:[ |
5008 | 870 |
DebugKeyboard ifTrue:[ |
871 |
Transcript showCR:'internal handling'. |
|
872 |
]. |
|
4811 | 873 |
^ super keyPress:shortCut x:x y:y |
5008 | 874 |
]. |
4803 | 875 |
]. |
1358
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
876 |
|
914 | 877 |
seq := kbdSequences at:rawKey ifAbsent:nil. |
878 |
seq notNil ifTrue:[ |
|
4294 | 879 |
DebugKeyboard ifTrue:[ |
5008 | 880 |
Transcript show:'seq ->' ; showCR:seq storeString. |
3758 | 881 |
]. |
4317 | 882 |
self send:(seq withoutCEscapes). |
914 | 883 |
^ self |
884 |
]. |
|
885 |
||
886 |
(rawKey startsWith:'Ctrl') ifTrue:[ |
|
887 |
rest := rawKey copyFrom:5. |
|
888 |
rest size == 1 ifTrue:[ |
|
889 |
rest := rest at:1. |
|
4336 | 890 |
(rest asLowercase between:$a and:$z) ifTrue:[ |
4294 | 891 |
DebugKeyboard ifTrue:[ |
5008 | 892 |
Transcript show:'ctrl ->' ; showCR:(Character controlCharacter:rest) storeString. |
893 |
]. |
|
894 |
(signalControlKeys and:[rawKey == #Ctrlc]) ifTrue:[ |
|
895 |
self doSendInterrupt. |
|
896 |
^ self. |
|
2192 | 897 |
]. |
4336 | 898 |
self sendCharacter:(Character controlCharacter:rest). |
914 | 899 |
^ self |
900 |
]. |
|
901 |
] |
|
902 |
]. |
|
903 |
||
5008 | 904 |
((rawKey startsWith:'Control') |
905 |
or:[ (rawKey startsWith:'Shift') |
|
906 |
or:[ (rawKey startsWith:'Alt') |
|
907 |
or:[ (rawKey = 'Ctrl') |
|
908 |
]]]) ifTrue:[ |
|
909 |
DebugKeyboard ifTrue:[ |
|
910 |
Transcript showCR:'modifier ignored'. |
|
911 |
]. |
|
934 | 912 |
^ self |
913 |
]. |
|
914 |
(rawKey startsWith:'Cmd') ifTrue:[ |
|
5008 | 915 |
DebugKeyboard ifTrue:[ |
916 |
Transcript showCR:'CMD handled internal'. |
|
917 |
]. |
|
950 | 918 |
^ super keyPress:aKey x:x y:y |
934 | 919 |
]. |
920 |
||
4294 | 921 |
DebugKeyboard ifTrue:[ |
5008 | 922 |
Transcript show:'unhandled: '; showCR:rawKey. |
2192 | 923 |
]. |
914 | 924 |
|
4294 | 925 |
" |
926 |
DebugKeyboard := true |
|
927 |
" |
|
928 |
||
4105 | 929 |
"Modified: / 25-01-2012 / 10:43:06 / cg" |
914 | 930 |
! |
931 |
||
4593 | 932 |
keyPressInLineEditMode:aKey |
933 |
"readline alike line editing. |
|
4815 | 934 |
cursorUp/down select a previous line from the history (unix shell bahevior). |
935 |
shift cursorUp selects a previous selected history line from the history (windows shell bahevior). |
|
4816 | 936 |
cursor left/right/^A/^E/backspace position/edit inside that line. |
4815 | 937 |
Return true, if the character was processed, |
4593 | 938 |
false if not. Then, the caller should proceed as usual." |
939 |
||
940 |
|clearLine| |
|
941 |
||
942 |
clearLine := |
|
943 |
[ |
|
944 |
lineBufferCursorPosition-1 timesRepeat:[ self deleteCharBeforeCursor ]. |
|
945 |
(lineBuffer size-(lineBufferCursorPosition-1)) timesRepeat:[ self deleteCharAtCursor]. |
|
946 |
]. |
|
947 |
||
948 |
"/ in lineEditMode, defer sending to the pty, until a newline is entered |
|
949 |
lineBuffer isNil ifTrue:[ |
|
950 |
lineBuffer := String new. |
|
951 |
lineBufferCursorPosition := 1. |
|
952 |
]. |
|
953 |
||
954 |
aKey isCharacter ifTrue:[ |
|
955 |
lineBuffer := (lineBuffer copyTo:lineBufferCursorPosition-1) |
|
956 |
, aKey |
|
957 |
, (lineBuffer copyFrom:lineBufferCursorPosition). |
|
958 |
self insertCharAtCursor:aKey. |
|
959 |
lineBufferCursorPosition := lineBufferCursorPosition + 1. |
|
960 |
^ true. |
|
961 |
]. |
|
4601 | 962 |
|
4593 | 963 |
aKey == #Return ifTrue:[ |
964 |
"/ as the pty is in echo mode, |
|
965 |
"/ we should either disable echo for the following, |
|
966 |
"/ or remove from the textview and let the program redraw them. |
|
967 |
"/ the second alternative looks easier for now... |
|
968 |
clearLine value. |
|
4604 | 969 |
self sendCR:lineBuffer. |
970 |
||
4815 | 971 |
lastSelectedLineBufferHistoryPosition := lineBufferHistoryPosition. |
972 |
||
4593 | 973 |
lineBufferHistory isNil ifTrue:[ |
974 |
lineBufferHistory := OrderedCollection new. |
|
975 |
]. |
|
4594 | 976 |
(lineBufferHistory size > 0 and:[lineBufferHistory last isEmpty]) ifTrue:[ |
977 |
lineBufferHistory removeLast |
|
978 |
]. |
|
4813 | 979 |
"/ do not remember repetitions |
980 |
(lineBufferHistory size > 0 and:[lineBufferHistory last = lineBuffer]) ifTrue:[ |
|
981 |
] ifFalse:[ |
|
982 |
lineBufferHistory addLast:lineBuffer. |
|
983 |
]. |
|
4593 | 984 |
lineBufferHistoryPosition := lineBufferHistory size + 1. |
985 |
lineBuffer := nil. |
|
4602 | 986 |
|
987 |
maxHistorySize notNil ifTrue:[ |
|
988 |
[ lineBufferHistory size > maxHistorySize] whileTrue:[ |
|
989 |
lineBufferHistory removeFirst. |
|
990 |
]. |
|
991 |
]. |
|
992 |
||
4593 | 993 |
^ true. |
994 |
]. |
|
995 |
||
996 |
aKey == #BackSpace ifTrue:[ |
|
997 |
lineBufferCursorPosition > 1 ifFalse:[ |
|
998 |
self beep. |
|
999 |
^ true |
|
1000 |
]. |
|
1001 |
lineBuffer := (lineBuffer copyTo:lineBufferCursorPosition-2) |
|
1002 |
, (lineBuffer copyFrom:lineBufferCursorPosition). |
|
1003 |
self deleteCharBeforeCursor. |
|
1004 |
lineBufferCursorPosition := lineBufferCursorPosition - 1. |
|
1005 |
^ true. |
|
1006 |
]. |
|
1007 |
||
4817 | 1008 |
((aKey == #BeginOfText) or:[aKey == #Ctrla]) ifTrue:[ |
4816 | 1009 |
lineBufferCursorPosition > 1 ifFalse:[ |
1010 |
self beep. |
|
1011 |
^ true |
|
1012 |
]. |
|
1013 |
lineBufferCursorPosition := 1. |
|
1014 |
self cursorToBeginOfLine. |
|
1015 |
^ true. |
|
1016 |
]. |
|
4817 | 1017 |
((aKey == #EndOfText) or:[aKey == #Ctrle]) ifTrue:[ |
4816 | 1018 |
lineBufferCursorPosition := lineBuffer size. |
1019 |
self cursorToEndOfLine. |
|
1020 |
^ true. |
|
1021 |
]. |
|
4593 | 1022 |
aKey == #CursorLeft ifTrue:[ |
1023 |
lineBufferCursorPosition > 1 ifFalse:[ |
|
1024 |
self beep. |
|
1025 |
^ true |
|
1026 |
]. |
|
1027 |
lineBufferCursorPosition := lineBufferCursorPosition - 1. |
|
1028 |
self cursorLeft. |
|
1029 |
^ true. |
|
1030 |
]. |
|
1031 |
aKey == #CursorRight ifTrue:[ |
|
4641 | 1032 |
lineBufferCursorPosition <= lineBuffer size ifFalse:[ |
4593 | 1033 |
self beep. |
1034 |
^ true |
|
1035 |
]. |
|
1036 |
lineBufferCursorPosition := lineBufferCursorPosition + 1. |
|
1037 |
self cursorRight. |
|
1038 |
^ true. |
|
1039 |
]. |
|
1040 |
aKey == #CursorUp ifTrue:[ |
|
4603 | 1041 |
(lineBufferHistoryPosition notNil and:[lineBufferHistoryPosition > 1]) ifFalse:[ |
4593 | 1042 |
self beep. |
1043 |
^ true |
|
1044 |
]. |
|
1045 |
||
4595 | 1046 |
"/ remember the current lineBuffer (but only if it is the last) |
4593 | 1047 |
lineBufferHistoryPosition > lineBufferHistory size ifTrue:[ |
1048 |
lineBufferHistory add:lineBuffer. |
|
1049 |
]. |
|
1050 |
clearLine value. |
|
1051 |
||
4815 | 1052 |
(self sensor shiftDown and:[lastSelectedLineBufferHistoryPosition notNil]) ifTrue:[ |
1053 |
lineBufferHistoryPosition := lastSelectedLineBufferHistoryPosition. |
|
1054 |
] ifFalse:[ |
|
1055 |
lineBufferHistoryPosition := lineBufferHistoryPosition - 1. |
|
1056 |
]. |
|
1057 |
"/ lastSelectedLineBufferHistoryPosition := lineBufferHistoryPosition. |
|
4839 | 1058 |
lineBuffer := lineBufferHistory at:lineBufferHistoryPosition ifAbsent:[lineBufferHistory last]. |
4593 | 1059 |
self insertStringAtCursor:lineBuffer. |
1060 |
lineBufferCursorPosition := lineBuffer size + 1. |
|
4819 | 1061 |
self makeCursorVisible. |
4593 | 1062 |
^ true. |
1063 |
]. |
|
1064 |
aKey == #CursorDown ifTrue:[ |
|
4603 | 1065 |
(lineBufferHistoryPosition notNil and:[lineBufferHistoryPosition < lineBufferHistory size]) ifFalse:[ |
4593 | 1066 |
self beep. |
1067 |
^ true |
|
1068 |
]. |
|
1069 |
||
1070 |
clearLine value. |
|
1071 |
||
1072 |
lineBufferHistoryPosition := lineBufferHistoryPosition + 1. |
|
4815 | 1073 |
"/ lastSelectedLineBufferHistoryPosition := lineBufferHistoryPosition. |
4593 | 1074 |
lineBuffer := lineBufferHistory at:lineBufferHistoryPosition. |
4594 | 1075 |
lineBufferHistoryPosition >= lineBufferHistory size ifTrue:[ |
1076 |
lineBufferHistory removeLast. |
|
1077 |
]. |
|
4593 | 1078 |
self insertStringAtCursor:lineBuffer. |
1079 |
lineBufferCursorPosition := lineBuffer size + 1. |
|
4819 | 1080 |
self makeCursorVisible. |
4593 | 1081 |
^ true. |
1082 |
]. |
|
1083 |
^ false. |
|
1084 |
! |
|
1085 |
||
914 | 1086 |
shellTerminated |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1087 |
"shell has terminated" |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1088 |
|
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1089 |
"/Delay waitForSeconds:10. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1090 |
[self readAnyAvailableData > 0] whileTrue:[Delay waitForSeconds:0.1]. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1091 |
"/ |
4265 | 1092 |
self closeDownShellAndStopReaderProcess. |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1093 |
|
946 | 1094 |
shellTerminateAction notNil ifTrue:[ |
1095 |
shellTerminateAction value |
|
1096 |
] ifFalse:[ |
|
1097 |
"/ may be removed ... |
|
4250 | 1098 |
self warn:(resources string:'shell terminated'). |
946 | 1099 |
] |
1100 |
||
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1101 |
"Modified: / 5.5.1999 / 18:43:22 / cg" |
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1102 |
! |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1103 |
|
4601 | 1104 |
shouldProcessInputInLineEditMode |
1105 |
"should input be processed in the readline edit mode?" |
|
1106 |
||
1107 |
|termiosInfo| |
|
1108 |
||
1109 |
lineEditMode == true ifFalse:[^ false]. |
|
1110 |
||
1111 |
"/ check if tty is in raw mode - then don't do lineEditMode |
|
1112 |
(OperatingSystem isUNIXlike |
|
1113 |
and:[ inStream isExternalStream ]) ifTrue:[ |
|
1114 |
termiosInfo := inStream tcgetattr. |
|
1115 |
((termiosInfo at:#lflags) at:#icanon) ifFalse:[^ false]. |
|
1116 |
]. |
|
1117 |
||
1118 |
"/ don't know how to do that on non-unix systems |
|
1119 |
^ true |
|
1120 |
! |
|
1121 |
||
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1122 |
sizeChanged:how |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1123 |
super sizeChanged:how. |
943 | 1124 |
self defineWindowSize. |
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1125 |
|
943 | 1126 |
"Modified: / 11.6.1998 / 22:51:48 / cg" |
914 | 1127 |
! ! |
1128 |
||
1129 |
!TerminalView methodsFor:'functions'! |
|
1130 |
||
1131 |
doBackspace |
|
1132 |
self cursorLeft. |
|
1133 |
self replaceCharAtCursor:(Character space). |
|
1134 |
self cursorLeft. |
|
1135 |
||
931 | 1136 |
"Modified: / 10.6.1998 / 17:09:12 / cg" |
914 | 1137 |
! |
1138 |
||
926 | 1139 |
doClearDisplay |
1420 | 1140 |
"clear everything" |
1141 |
||
1000 | 1142 |
self doClearEntireScreen. |
1143 |
||
1144 |
"Modified: / 21.7.1998 / 20:05:35 / cg" |
|
1145 |
! |
|
1146 |
||
1420 | 1147 |
doClearEntireLine |
1148 |
"clear the cursor line. cursor position remains unchanged" |
|
1149 |
||
1150 |
self at:cursorLine put:'' |
|
1151 |
! |
|
1152 |
||
1000 | 1153 |
doClearEntireScreen |
1420 | 1154 |
"clear everything" |
1155 |
||
4668 | 1156 |
firstLineShown to:(list size) do:[:lNr | |
1157 |
self at:lNr put:'' |
|
926 | 1158 |
]. |
922 | 1159 |
|
1000 | 1160 |
"Modified: / 21.7.1998 / 20:00:19 / cg" |
1161 |
"Created: / 21.7.1998 / 20:05:24 / cg" |
|
926 | 1162 |
! |
1163 |
||
1000 | 1164 |
doClearFromBeginningOfLine |
1420 | 1165 |
"clear from beginning of line to the cursorPosition" |
1166 |
||
1000 | 1167 |
|l| |
1168 |
||
1169 |
l := self listAt:cursorLine. |
|
1170 |
l notNil ifTrue:[ |
|
1171 |
(l size >= (cursorCol-1)) ifTrue:[ |
|
1172 |
l := l copy from:1 to:cursorCol-1 put:(Character space). |
|
1173 |
] ifFalse:[ |
|
1174 |
l := nil. |
|
1175 |
]. |
|
1176 |
self withoutRedrawAt:cursorLine put:l. |
|
1177 |
self invalidateLine:cursorLine |
|
1178 |
"/ self at:cursorLine put:l. |
|
1179 |
] |
|
1180 |
||
1181 |
"Modified: / 20.6.1998 / 19:10:21 / cg" |
|
1182 |
"Created: / 21.7.1998 / 20:10:58 / cg" |
|
1183 |
! |
|
1184 |
||
1185 |
doClearFromBeginningOfScreen |
|
1420 | 1186 |
"clear from beginning of the screen to the cursorPosition" |
1187 |
||
1000 | 1188 |
self doClearFromBeginningOfLine. |
4668 | 1189 |
cursorLine-1 to:firstLineShown do:[:lNr | |
1190 |
self at:lNr put:'' |
|
922 | 1191 |
]. |
1192 |
||
926 | 1193 |
"Modified: / 10.6.1998 / 14:45:43 / cg" |
1000 | 1194 |
"Created: / 21.7.1998 / 20:08:29 / cg" |
926 | 1195 |
! |
1196 |
||
1197 |
doClearToEndOfLine |
|
1420 | 1198 |
"clear from the cursorPosition to the end of the line" |
1199 |
||
926 | 1200 |
|l| |
1201 |
||
1202 |
l := self listAt:cursorLine. |
|
931 | 1203 |
(l size >= (cursorCol-1)) ifTrue:[ |
951 | 1204 |
l notNil ifTrue:[ |
1205 |
l := l copyTo:cursorCol-1. |
|
979 | 1206 |
self withoutRedrawAt:cursorLine put:l. |
1207 |
self invalidateLine:cursorLine |
|
1208 |
"/ self at:cursorLine put:l. |
|
951 | 1209 |
] |
926 | 1210 |
] |
1211 |
||
1212 |
"Created: / 10.6.1998 / 14:45:01 / cg" |
|
979 | 1213 |
"Modified: / 20.6.1998 / 19:10:21 / cg" |
914 | 1214 |
! |
1215 |
||
1000 | 1216 |
doClearToEndOfScreen |
1420 | 1217 |
"clear from the cursorPosition to the end of the screen" |
1218 |
||
1000 | 1219 |
self doClearToEndOfLine. |
4668 | 1220 |
cursorLine+1 to:(list size) do:[:lNr | |
1221 |
self at:lNr put:'' |
|
1000 | 1222 |
]. |
1223 |
||
1224 |
"Modified: / 10.6.1998 / 14:45:43 / cg" |
|
1225 |
"Created: / 21.7.1998 / 20:06:14 / cg" |
|
1226 |
! |
|
1227 |
||
926 | 1228 |
doCursorDown:n |
1420 | 1229 |
"move the cursor down by n lines" |
1230 |
||
979 | 1231 |
|wasOn rEnd| |
926 | 1232 |
|
979 | 1233 |
"/ rangeEndLine == numberOfLines ifTrue:[ |
1234 |
"/ ^ super cursorDown:n |
|
1235 |
"/ ]. |
|
1236 |
cursorLine + 1 - firstLineShown + n <= rangeEndLine ifTrue:[ |
|
951 | 1237 |
"/ no special action req'd |
1238 |
^ super cursorDown:n |
|
1239 |
]. |
|
979 | 1240 |
|
951 | 1241 |
n timesRepeat:[ |
1242 |
wasOn := self hideCursor. |
|
979 | 1243 |
rEnd := rangeEndLine+firstLineShown-1. |
1244 |
cursorLine == rEnd ifTrue:[ |
|
1245 |
self deleteLine:(rangeStartLine+firstLineShown-1). |
|
1246 |
self insertLine:'' before:rEnd. |
|
951 | 1247 |
] ifFalse:[ |
1248 |
super cursorDown |
|
1249 |
]. |
|
979 | 1250 |
wasOn ifTrue:[self showCursor]. "/ self makeCursorVisibleAndShowCursor:wasOn. |
951 | 1251 |
] |
1252 |
||
979 | 1253 |
"Modified: / 20.6.1998 / 20:29:39 / cg" |
926 | 1254 |
! |
1255 |
||
914 | 1256 |
doCursorHome |
1420 | 1257 |
"move the cursor to the home position" |
1258 |
||
938 | 1259 |
self cursorVisibleLine:1 col:1 |
1260 |
"/ super cursorHome |
|
1261 |
||
1262 |
"Modified: / 10.6.1998 / 20:47:31 / cg" |
|
914 | 1263 |
! |
1264 |
||
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1265 |
doCursorLeft:n |
1420 | 1266 |
"move the cursor to the left by n columns" |
1267 |
||
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1268 |
n timesRepeat:[ |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1269 |
super cursorLeft |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1270 |
] |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1271 |
|
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1272 |
"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
|
1273 |
! |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1274 |
|
914 | 1275 |
doCursorNewLine |
1420 | 1276 |
"move the cursor down to the next line (col remains unchanged)" |
1277 |
||
931 | 1278 |
super cursorDown:1 |
1279 |
||
1280 |
"Modified: / 10.6.1998 / 16:55:57 / cg" |
|
914 | 1281 |
! |
1282 |
||
1283 |
doCursorReturn |
|
1420 | 1284 |
"move the cursor down and left to the beginning to the next line" |
1285 |
||
914 | 1286 |
super cursorToBeginOfLine |
1287 |
! |
|
1288 |
||
926 | 1289 |
doCursorRight:n |
1420 | 1290 |
"move the cursor to the right by n columns" |
1291 |
||
926 | 1292 |
self cursorCol:(cursorCol + n) |
1293 |
||
1294 |
"Created: / 10.6.1998 / 15:10:08 / cg" |
|
1295 |
! |
|
1296 |
||
951 | 1297 |
doCursorUp:n |
1420 | 1298 |
"move the cursor up by n lines" |
1299 |
||
979 | 1300 |
|wasOn rStart| |
926 | 1301 |
|
979 | 1302 |
"/ rangeStartLine == 1 ifTrue:[ |
1303 |
"/ ^ super cursorUp:n |
|
1304 |
"/ ]. |
|
1305 |
cursorLine + 1 - firstLineShown - n >= rangeStartLine ifTrue:[ |
|
951 | 1306 |
"/ no special action req'd |
1307 |
^ super cursorUp:n |
|
1308 |
]. |
|
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1309 |
n timesRepeat:[ |
951 | 1310 |
wasOn := self hideCursor. |
979 | 1311 |
rStart := rangeStartLine+firstLineShown-1. |
1312 |
cursorLine == rStart ifTrue:[ |
|
1313 |
(rangeEndLine+firstLineShown-1) <= list size ifTrue:[ |
|
1314 |
self deleteLine:(rangeEndLine+firstLineShown-1). |
|
1315 |
self insertLine:'' before:rStart. |
|
1316 |
]. |
|
951 | 1317 |
] ifFalse:[ |
1318 |
super cursorUp |
|
1319 |
]. |
|
1320 |
self makeCursorVisibleAndShowCursor:wasOn. |
|
942
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1321 |
] |
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1322 |
|
1f4fa3a6faec
send a sigWINCH whenever the views size changes.
Claus Gittinger <cg@exept.de>
parents:
940
diff
changeset
|
1323 |
"Created: / 11.6.1998 / 22:29:46 / cg" |
979 | 1324 |
"Modified: / 20.6.1998 / 20:30:34 / cg" |
914 | 1325 |
! ! |
1326 |
||
2501 | 1327 |
!TerminalView methodsFor:'initialization & release'! |
914 | 1328 |
|
1329 |
closeDownShell |
|
4265 | 1330 |
"shut down my shell process." |
1420 | 1331 |
|
1009 | 1332 |
|pid| |
926 | 1333 |
|
1334 |
(pid := shellPid) notNil ifTrue:[ |
|
2192 | 1335 |
Debug ifTrue:[ |
4265 | 1336 |
Transcript show:'killing shell pid='; showCR:pid. |
2192 | 1337 |
]. |
4958 | 1338 |
OperatingSystem isMSWINDOWSlike ifFalse:[ |
1339 |
OperatingSystem terminateProcessGroup:pid. |
|
1340 |
]. |
|
926 | 1341 |
OperatingSystem terminateProcess:pid. |
4959 | 1342 |
Delay waitForSeconds:0.2. |
925 | 1343 |
shellPid notNil ifTrue:[ |
4959 | 1344 |
"/ Delay waitForSeconds:1. |
4958 | 1345 |
shellPid notNil ifTrue:[ |
1346 |
OperatingSystem isMSWINDOWSlike ifFalse:[ |
|
1347 |
OperatingSystem killProcessGroup:pid. |
|
1348 |
]. |
|
1349 |
OperatingSystem killProcess:pid. |
|
1350 |
shellPid := nil. |
|
1341
3467ffd6eb35
first attempt in supporting win32;
Claus Gittinger <cg@exept.de>
parents:
1339
diff
changeset
|
1351 |
]. |
925 | 1352 |
]. |
926 | 1353 |
OperatingSystem closePid:pid. |
914 | 1354 |
]. |
4265 | 1355 |
! |
914 | 1356 |
|
4265 | 1357 |
closeDownShellAndStopReaderProcess |
1358 |
"shut down my shell process and stop the background reader thread." |
|
1359 |
||
1360 |
self closeDownShell. |
|
1009 | 1361 |
self stopReaderProcess. |
4265 | 1362 |
self closeStreams |
1009 | 1363 |
|
4265 | 1364 |
"Modified: / 5.5.1999 / 18:43:02 / cg" |
1365 |
! |
|
1366 |
||
1367 |
closeStreams |
|
4576 | 1368 |
|s| |
1369 |
||
1370 |
(s := inStream) notNil ifTrue:[ |
|
1371 |
inStream := nil. |
|
4654 | 1372 |
(s isStream and:[s isOpen]) ifTrue:[ |
1373 |
s close |
|
1374 |
]. |
|
914 | 1375 |
]. |
4576 | 1376 |
(s := outStream) notNil ifTrue:[ |
1377 |
outStream := nil. |
|
4654 | 1378 |
(s isStream and:[s isOpen]) ifTrue:[ |
1379 |
s close. |
|
1380 |
]. |
|
914 | 1381 |
]. |
924 | 1382 |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1383 |
"Modified: / 5.5.1999 / 18:43:02 / cg" |
914 | 1384 |
! |
1385 |
||
1386 |
escapeSequences:codes |
|
1420 | 1387 |
"setup my escape sequences" |
1388 |
||
914 | 1389 |
|tree| |
1390 |
||
1391 |
tree isNil ifTrue:[tree := escapeSequenceTree := IdentityDictionary new]. |
|
1392 |
||
1393 |
codes do:[:specEntry | |
|
1394 |
|sequence function| |
|
1395 |
||
4105 | 1396 |
sequence := (specEntry at:1) withoutCEscapes. |
914 | 1397 |
function := specEntry at:2. |
1398 |
||
1399 |
tree := escapeSequenceTree. |
|
1400 |
||
1401 |
sequence keysAndValuesDo:[:idx :char | |
|
1402 |
|followup| |
|
1403 |
||
1404 |
idx == sequence size ifTrue:[ |
|
1405 |
tree at:char put:function |
|
1406 |
] ifFalse:[ |
|
1407 |
followup := tree at:char ifAbsent:nil. |
|
1408 |
followup isNil ifTrue:[ |
|
1409 |
tree at:char put:(followup := IdentityDictionary new). |
|
1410 |
]. |
|
1411 |
tree := followup |
|
1412 |
] |
|
1413 |
] |
|
1414 |
]. |
|
918 | 1415 |
escapeLeadingChars := escapeSequenceTree keys asSet. |
1416 |
escapeLeadingChars add:(Character cr). |
|
1417 |
escapeLeadingChars add:(Character return). |
|
1418 |
escapeLeadingChars add:(Character backspace). |
|
1419 |
||
1420 |
escapeLeadingChars := escapeLeadingChars asArray |
|
1421 |
||
4105 | 1422 |
"Modified: / 25-01-2012 / 10:42:46 / cg" |
914 | 1423 |
! |
1424 |
||
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1425 |
flushInput |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1426 |
|sensor| |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1427 |
|
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1428 |
"/ flush any leftover input-processing events |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1429 |
(sensor := self sensor) notNil ifTrue:[ |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1430 |
sensor flushEventsFor:self withType:#processInput:n:. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1431 |
] |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1432 |
|
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1433 |
"Modified: / 21.7.1998 / 19:00:13 / cg" |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1434 |
"Created: / 5.5.1999 / 18:41:42 / cg" |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1435 |
! |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1436 |
|
2163 | 1437 |
initStyle |
1438 |
super initStyle. |
|
1439 |
"/ self foregroundColor:Color green. |
|
1440 |
"/ self backgroundColor:Color black. |
|
1441 |
! |
|
1442 |
||
914 | 1443 |
initialize |
2194 | 1444 |
|
914 | 1445 |
super initialize. |
1446 |
||
4803 | 1447 |
sendControlKeys := true. |
5008 | 1448 |
signalControlKeys := OperatingSystem isMSWINDOWSlike. |
914 | 1449 |
showMatchingParenthesis := false. |
4288 | 1450 |
self insertMode: false. |
936 | 1451 |
alwaysAppendAtEnd := false. |
4315 | 1452 |
collectSize := 4096. |
1453 |
sizeOfOutstandingInputToBeProcessed := 0. |
|
977 | 1454 |
st80Mode := false. |
1455 |
trimBlankLines := true. |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1456 |
localEcho := false. |
2078 | 1457 |
inputTranslateCRToNL := false. |
4604 | 1458 |
inputTranslateCRToCRNL := OperatingSystem isMSWINDOWSlike. |
4324 | 1459 |
inputTranslateBackspaceToDelete := false. |
5008 | 1460 |
inputIsUTF8 := UserPreferences current terminalInputIsUTF8. |
1461 |
outputIsUTF8 := false. "/ currently unused. |
|
2268 | 1462 |
autoWrapFlag := true. |
4299 | 1463 |
noColors := false. |
4612 | 1464 |
doUTF := UserPreferences current terminalOutputIsUTF8. |
4604 | 1465 |
lineEditMode := OperatingSystem isMSWINDOWSlike. |
4602 | 1466 |
maxHistorySize := maxHistorySize ? DefaultMaxHistorySize. |
4641 | 1467 |
ignoreOutput := false. |
4602 | 1468 |
|
2268 | 1469 |
"/ cursorType := #block. |
4452 | 1470 |
"/ cursorTypeNoFocus := #frame. |
1471 |
||
4446
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
1472 |
state := 0. |
914 | 1473 |
|
926 | 1474 |
numberOfColumns := 80. |
979 | 1475 |
numberOfLines := 24. |
954 | 1476 |
rangeStartLine := 1. |
1477 |
rangeEndLine := numberOfLines. |
|
926 | 1478 |
|
2423
d2685982f94f
tabs are always in multiples of 8 (no matter what users pref are)
Claus Gittinger <cg@exept.de>
parents:
2356
diff
changeset
|
1479 |
self setTab8. |
d2685982f94f
tabs are always in multiples of 8 (no matter what users pref are)
Claus Gittinger <cg@exept.de>
parents:
2356
diff
changeset
|
1480 |
|
914 | 1481 |
self initializeKeyboardSequences. |
1482 |
list := OrderedCollection new:24 withAll:''. |
|
1483 |
||
2577 | 1484 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
1485 |
kbdSequences at:#Return put:'\r\n'. |
|
1486 |
]. |
|
914 | 1487 |
self initializeKeyboardMap. |
1488 |
||
1489 |
" |
|
1490 |
VT52TerminalView openShell |
|
926 | 1491 |
VT100TerminalView openShell |
914 | 1492 |
" |
926 | 1493 |
|
4315 | 1494 |
"Modified: / 30-07-2013 / 10:43:07 / cg" |
914 | 1495 |
! |
1496 |
||
1497 |
initializeKeyboardMap |
|
1349 | 1498 |
|keys ctrlKeys cmdKeys| |
914 | 1499 |
|
1349 | 1500 |
"/ setup my own keyboardMap, where control-keys |
1501 |
"/ (and some Cmd-keys) are not translated. |
|
5006 | 1502 |
kbdMap := device keyboardMap copy. |
1349 | 1503 |
keys := kbdMap keys. |
914 | 1504 |
|
1349 | 1505 |
ctrlKeys := keys select:[:key | key startsWith:'Ctrl']. |
914 | 1506 |
ctrlKeys do:[:key | kbdMap removeKey:key]. |
950 | 1507 |
|
1349 | 1508 |
cmdKeys := keys select:[:key | key startsWith:'Cmd']. |
1509 |
cmdKeys do:[:key | |val| |
|
1510 |
val := kbdMap at:key. |
|
1511 |
val isSymbol ifTrue:[ |
|
2506 | 1512 |
(#(Copy Paste SaveAs Print Find FindNext FindPrev GotoLine) includes:val) ifFalse:[ |
1349 | 1513 |
kbdMap removeKey:key |
1514 |
] |
|
950 | 1515 |
] |
1516 |
]. |
|
914 | 1517 |
|
1518 |
kbdMap removeKey:#Delete ifAbsent:[]. |
|
1519 |
kbdMap removeKey:#BackSpace ifAbsent:[]. |
|
1520 |
||
1521 |
" |
|
1522 |
VT52TerminalView openShell |
|
1523 |
" |
|
950 | 1524 |
|
1349 | 1525 |
"Modified: / 29.4.1999 / 14:25:24 / cg" |
914 | 1526 |
! |
1527 |
||
1528 |
initializeKeyboardSequences |
|
1358
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
1529 |
kbdSequences := (self anyKeyCodes) |
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
1530 |
|
ec94a03e4585
Ctrl-keys which are mapped to function keys
Claus Gittinger <cg@exept.de>
parents:
1354
diff
changeset
|
1531 |
"Modified: / 5.5.1999 / 15:01:09 / cg" |
914 | 1532 |
! |
1533 |
||
1534 |
keyboardMap |
|
934 | 1535 |
"return my keyboard map. This has control keys removed and |
1536 |
those will be passed unchanged to the shell" |
|
1537 |
||
914 | 1538 |
^ kbdMap |
934 | 1539 |
|
1540 |
"Modified: / 10.6.1998 / 17:46:59 / cg" |
|
914 | 1541 |
! |
1542 |
||
1319
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1543 |
reinitialize |
1833 | 1544 |
"reinit after a snapIn. |
1545 |
this is invoked (by the system thread) after a snapShot image restart" |
|
1319
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1546 |
|
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1547 |
super reinitialize. |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1548 |
|
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1549 |
shellPid := nil. |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1550 |
|
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1551 |
self stopReaderProcess. |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1552 |
self flushInput. |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1553 |
|
1319
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1554 |
readerProcess := nil. |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1555 |
inStream := outStream := nil. |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1556 |
|
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1557 |
"/ 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
|
1558 |
[ |
1322 | 1559 |
"/ Delay waitForSeconds:0.5. |
1319
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1560 |
self doClearEntireScreen. |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1561 |
self cursorLine:1 col:1. |
1321
9a312fa98358
also throw away scrolled text whith restart.
Claus Gittinger <cg@exept.de>
parents:
1320
diff
changeset
|
1562 |
self contents:nil. |
1319
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1563 |
self flash. |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1564 |
|
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1565 |
"/ |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1566 |
"/ 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
|
1567 |
"/ |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1568 |
self startCommand:shellCommand in:shellDirectory. |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1569 |
] forkAt:8 |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1570 |
|
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
1571 |
"Modified: / 5.5.1999 / 18:41:55 / cg" |
1319
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1572 |
! |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1573 |
|
2155 | 1574 |
release |
1575 |
"release myself - shut down the shell, stop the reader thread." |
|
1576 |
||
4265 | 1577 |
[ |
1578 |
self closeDownShellAndStopReaderProcess. |
|
1579 |
self flushInput. |
|
2341
9b19cf22a099
release pipe in background (faster shutdown)
Claus Gittinger <cg@exept.de>
parents:
2268
diff
changeset
|
1580 |
] fork. |
4655 | 1581 |
super release. |
1582 |
||
1583 |
"Modified: / 17-07-2014 / 19:29:55 / cg" |
|
985
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
1584 |
! ! |
275897f12b52
added #openOnCommand:, to allow view on any (non-shell)
Claus Gittinger <cg@exept.de>
parents:
979
diff
changeset
|
1585 |
|
2501 | 1586 |
!TerminalView methodsFor:'initialization-shell'! |
1587 |
||
2778 | 1588 |
basicStartCommand:aCommand in:aDirectory |
2501 | 1589 |
"start a command on a pseudo terminal. If the command arg is nil, |
1590 |
a shell is started. If aDirectory is not nil, the command is |
|
1591 |
executed in that directory. |
|
1592 |
Also fork a reader process, to read the shells output and |
|
1593 |
tell me, whenever something arrives" |
|
1594 |
||
1595 |
|pty slaveFD execFdArray blocked exitStatus |
|
1596 |
stxToCommandPipe commandToStxPipe cmd shell args env shellAndArgs| |
|
1597 |
||
1598 |
shellCommand := aCommand. |
|
1599 |
shellDirectory := aDirectory. |
|
1600 |
||
1601 |
self create. "/ need my windowID (to pass down in environment) |
|
1602 |
||
1603 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
1604 |
"use two pipes to COMMAND.COM" |
|
2538
2ee2ed3bad39
Move makePTYPair to NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
2506
diff
changeset
|
1605 |
stxToCommandPipe := NonPositionableExternalStream makePipe. |
2501 | 1606 |
stxToCommandPipe isNil ifTrue:[ |
4250 | 1607 |
self warn:(resources string:'Could not create pipe to COMMAND.COM.'). |
1608 |
^ self. |
|
2501 | 1609 |
]. |
1610 |
||
2538
2ee2ed3bad39
Move makePTYPair to NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
2506
diff
changeset
|
1611 |
commandToStxPipe := NonPositionableExternalStream makePipe. |
2501 | 1612 |
commandToStxPipe isNil ifTrue:[ |
4250 | 1613 |
self warn:(resources string:'Could not create pipe from COMMAND.COM.'). |
1614 |
^ self. |
|
2501 | 1615 |
]. |
1616 |
||
1617 |
"/ pipe readSide is p at:1; |
|
1618 |
"/ writeSide is p at:2 |
|
1619 |
||
1620 |
slaveFD := (commandToStxPipe at:2) fileDescriptor. |
|
1621 |
execFdArray := Array |
|
1622 |
with:(stxToCommandPipe at:1) fileDescriptor "stdin" |
|
1623 |
with:slaveFD "stdout" |
|
1624 |
with:slaveFD. "stderr" |
|
1625 |
||
1626 |
outStream := commandToStxPipe at:1. |
|
1627 |
inStream := stxToCommandPipe at:2. |
|
1628 |
||
4655 | 1629 |
self defineWindowSize. "/ does not really work on windows (need help) |
1630 |
||
2501 | 1631 |
shellAndArgs := OperatingSystem commandAndArgsForOSCommand:aCommand. |
1632 |
shell := shellAndArgs at:1. |
|
1633 |
args := (shellAndArgs at:2) ? ''. |
|
1634 |
] ifFalse:[ |
|
1635 |
"Use a pseudo-tty" |
|
2538
2ee2ed3bad39
Move makePTYPair to NonPositionableExternalStream
Stefan Vogel <sv@exept.de>
parents:
2506
diff
changeset
|
1636 |
pty := NonPositionableExternalStream makePTYPair. |
2501 | 1637 |
pty isNil ifTrue:[ |
1638 |
self warn:'Cannot open pty.'. |
|
1639 |
^ self. |
|
1640 |
]. |
|
1641 |
||
1642 |
"/ pty at:1 is the master; |
|
1643 |
"/ pty at:2 is the slave |
|
1644 |
inStream := outStream := (pty at:1). |
|
1645 |
||
1646 |
self defineWindowSize. |
|
4655 | 1647 |
|
2501 | 1648 |
"/ fork a shell process on the slave-side |
1649 |
slaveFD := (pty at:2) fileDescriptor. |
|
1650 |
execFdArray := Array with:slaveFD with:slaveFD with:slaveFD. |
|
1651 |
||
1652 |
aCommand isNil ifTrue:[ |
|
1653 |
shell := OperatingSystem getEnvironment:'SHELL'. |
|
1654 |
shell size == 0 ifTrue:[ |
|
1655 |
shell := '/bin/sh'. |
|
1656 |
]. |
|
1657 |
cmd := shell asFilename baseName. |
|
1658 |
args := (Array with:cmd). |
|
1659 |
] ifFalse:[ |
|
1660 |
shell := '/bin/sh'. |
|
1661 |
args := (Array with:'sh' with:'-c' with:aCommand). |
|
1662 |
]. |
|
1663 |
env := Dictionary new. |
|
1664 |
env at:'SHELL' put:shell. |
|
1665 |
env at:'TERM' put:(self terminalType). |
|
4222 | 1666 |
env at:'HOME' put:(OperatingSystem getEnvironment:'HOME'). |
1667 |
env at:'USER' put:(OperatingSystem getEnvironment:'USER'). |
|
2501 | 1668 |
env at:'LINES' put:(numberOfLines printString). |
1669 |
env at:'COLUMNS' put:(numberOfColumns printString). |
|
5021 | 1670 |
(device platformName == #X11 and:[self drawableId notNil]) ifTrue:[ |
4518 | 1671 |
env at:'WINDOWID' put:(self drawableId address printString). |
2501 | 1672 |
]. |
1673 |
]. |
|
1674 |
||
1675 |
blocked := OperatingSystem blockInterrupts. |
|
1676 |
||
1677 |
shellPid := Processor |
|
1678 |
monitor:[ |
|
1679 |
OperatingSystem |
|
1680 |
exec:shell |
|
1681 |
withArguments:args |
|
1682 |
environment:env |
|
1683 |
fileDescriptors:execFdArray |
|
1684 |
fork:true |
|
1685 |
newPgrp:true |
|
1686 |
inDirectory:aDirectory. |
|
1687 |
] |
|
1688 |
action:[:status | |
|
1689 |
Debug ifTrue:[ |
|
4325 | 1690 |
Transcript showCR:'shell status change'. |
1691 |
Transcript show:' pid:'; showCR:status pid. |
|
1692 |
Transcript show:' status:'; showCR:status status. |
|
1693 |
Transcript show:' code:'; showCR:status code. |
|
1694 |
Transcript show:' core:'; showCR:status core. |
|
2501 | 1695 |
]. |
1696 |
status stillAlive ifFalse:[ |
|
1697 |
exitStatus := status. |
|
1698 |
OperatingSystem closePid:shellPid. |
|
1699 |
shellPid := nil. |
|
1700 |
self pushEvent:#shellTerminated |
|
1701 |
]. |
|
1702 |
]. |
|
1703 |
||
1704 |
blocked ifFalse:[ |
|
1705 |
OperatingSystem unblockInterrupts |
|
1706 |
]. |
|
1707 |
||
1708 |
"close the slave side of the pty/pipes (only used by the child)" |
|
1709 |
pty notNil ifTrue:[ |
|
1710 |
(pty at:2) close. |
|
1711 |
]. |
|
1712 |
||
1713 |
commandToStxPipe notNil ifTrue:[ |
|
1714 |
(commandToStxPipe at:2) close. |
|
1715 |
(stxToCommandPipe at:1) close. |
|
1716 |
]. |
|
1717 |
||
1718 |
shellPid isNil ifTrue:[ |
|
1719 |
self warn:'Cannot start shell'. |
|
4327 | 1720 |
self closeStreams. |
2501 | 1721 |
^ self. |
1722 |
]. |
|
1723 |
||
4655 | 1724 |
"Created: / 20-07-1998 / 18:19:32 / cg" |
1725 |
"Modified: / 17-07-2014 / 19:43:00 / cg" |
|
2778 | 1726 |
! |
1727 |
||
1728 |
startCommand:aCommand |
|
1729 |
"start a command on a pseudo terminal. If the command arg is nil, |
|
1730 |
a shell is started. The command is started in the current directory. |
|
1731 |
Also fork a reader process, to read the shells output and |
|
1732 |
tell me, whenever something arrives" |
|
1733 |
||
1734 |
self startCommand:aCommand in:nil |
|
1735 |
||
1736 |
"Modified: / 20.7.1998 / 18:30:24 / cg" |
|
1737 |
! |
|
1738 |
||
1739 |
startCommand:aCommand in:aDirectory |
|
1740 |
"start a command on a pseudo terminal. If the command arg is nil, |
|
1741 |
a shell is started. If aDirectory is not nil, the command is |
|
1742 |
executed in that directory. |
|
1743 |
Also fork a reader process, to read the shells output and |
|
1744 |
tell me, whenever something arrives" |
|
1745 |
||
1746 |
self basicStartCommand:aCommand in:aDirectory. |
|
1747 |
self startReaderProcessWhenVisible. |
|
2501 | 1748 |
|
1749 |
"Created: / 20.7.1998 / 18:19:32 / cg" |
|
1750 |
"Modified: / 5.5.1999 / 17:28:37 / cg" |
|
1751 |
! |
|
1752 |
||
1753 |
startShell |
|
1754 |
"start a shell on a pseudo terminal in the current directory. |
|
1755 |
Also fork a reader process, to read the shells output and |
|
1756 |
tell me, whenever something arrives" |
|
1757 |
||
1758 |
^ self startCommand:nil |
|
1759 |
||
1760 |
" |
|
1761 |
VT100TerminalView openShell |
|
1762 |
" |
|
1763 |
||
1764 |
"Modified: / 20.7.1998 / 18:29:54 / cg" |
|
1765 |
! |
|
1766 |
||
1767 |
startShellIn:aDirectory |
|
1768 |
"start a shell on a pseudo terminal in some directory. |
|
1769 |
Also fork a reader process, to read the shells output and |
|
1770 |
tell me, whenever something arrives" |
|
1771 |
||
2778 | 1772 |
self startCommand:nil in:aDirectory |
2501 | 1773 |
|
1774 |
" |
|
1775 |
VT100TerminalView openShellIn:'/etc' |
|
1776 |
" |
|
1777 |
||
1778 |
"Modified: / 20.7.1998 / 18:29:46 / cg" |
|
1779 |
! ! |
|
1780 |
||
914 | 1781 |
!TerminalView methodsFor:'menu'! |
1782 |
||
3225 | 1783 |
doClear |
1784 |
"reset the scroll-range etc, clear the text buffer" |
|
1785 |
||
1786 |
rangeStartLine := 1. |
|
1787 |
rangeEndLine := numberOfLines. |
|
1788 |
||
1789 |
self normal. |
|
1790 |
self clear. |
|
1791 |
||
1792 |
"Created: / 03-04-2007 / 08:58:59 / cg" |
|
1793 |
! |
|
1794 |
||
1319
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1795 |
doReset |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1796 |
"reset the scroll-range; |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1797 |
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
|
1798 |
|
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1799 |
rangeStartLine := 1. |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1800 |
rangeEndLine := numberOfLines. |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1801 |
|
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1802 |
self normal. |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1803 |
|
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1804 |
! |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1805 |
|
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1806 |
doSendInterrupt |
1420 | 1807 |
"send an INT-signal to the shell (UNIX only)" |
1808 |
||
4338 | 1809 |
|status| |
1810 |
||
5008 | 1811 |
DebugKeyboard ifTrue:[ |
1812 |
Transcript showCR:'interrupt!!'. |
|
1813 |
]. |
|
1814 |
||
2597 | 1815 |
shellPid notNil ifTrue:[ |
4306 | 1816 |
OperatingSystem isUNIXlike ifTrue:[ |
4956 | 1817 |
OperatingSystem interruptProcessGroup:shellPid. |
1818 |
OperatingSystem interruptProcess:shellPid. |
|
1819 |
"/ status := OperatingSystem childProcessWait:false pid:shellPid. |
|
4306 | 1820 |
] ifFalse:[ |
1821 |
self warn:'unimplemented for DOS' |
|
1822 |
] |
|
5008 | 1823 |
] ifFalse:[ |
1824 |
'VT100: no shell' infoPrintCR. |
|
2597 | 1825 |
]. |
1319
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1826 |
|
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1827 |
"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
|
1828 |
! |
0f19d022f577
restart shell when coming up via a snapshot
Claus Gittinger <cg@exept.de>
parents:
1317
diff
changeset
|
1829 |
|
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1830 |
doSendKillSignal |
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1831 |
"send a KILL-signal to the shell (UNIX only)" |
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1832 |
|
4338 | 1833 |
|status| |
1834 |
||
5008 | 1835 |
DebugKeyboard ifTrue:[ |
1836 |
Transcript showCR:'kill!!'. |
|
1837 |
]. |
|
2597 | 1838 |
shellPid notNil ifTrue:[ |
4306 | 1839 |
OperatingSystem isUNIXlike ifTrue:[ |
4956 | 1840 |
OperatingSystem killProcessGroup:shellPid. |
1841 |
OperatingSystem killProcess:shellPid. |
|
4338 | 1842 |
status := OperatingSystem childProcessWait:false pid:shellPid. |
4306 | 1843 |
] ifFalse:[ |
1844 |
self warn:'unimplemented for DOS' |
|
1845 |
] |
|
5008 | 1846 |
] ifFalse:[ |
1847 |
'VT100: no shell' infoPrintCR. |
|
2597 | 1848 |
] |
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1849 |
! |
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1850 |
|
914 | 1851 |
editMenu |
1852 |
"return the views middleButtonMenu" |
|
1853 |
||
1347 | 1854 |
<resource: #keyboard (#Copy #Paste #Print #SaveAs #Print)> |
914 | 1855 |
<resource: #programMenu> |
1856 |
||
4487 | 1857 |
|items subMenu moreMenu m sensor| |
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1858 |
|
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1859 |
items := #( |
3225 | 1860 |
('Interrupt' doSendInterrupt ) |
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1861 |
('Kill' doSendKillSignal) |
3225 | 1862 |
('-' ) |
1863 |
('Clear' doClear ) |
|
1864 |
('Reset' doReset ) |
|
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1865 |
). |
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1866 |
subMenu := PopUpMenu itemList:items resources:resources. |
914 | 1867 |
|
4487 | 1868 |
items := #( |
1869 |
('Open FileBrowser on It' openFileBrowserOnIt ) |
|
1870 |
). |
|
1871 |
moreMenu := PopUpMenu itemList:items resources:resources. |
|
1872 |
||
914 | 1873 |
((sensor := self sensor) notNil and:[sensor ctrlDown]) ifTrue:[ |
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1874 |
m := subMenu. |
914 | 1875 |
] ifFalse:[ |
1876 |
items := #( |
|
2075 | 1877 |
('Copy' copySelection Copy ) |
1878 |
('Paste' pasteOrReplace Paste ) |
|
914 | 1879 |
('-' ) |
2506 | 1880 |
('Search...' search Find) |
1881 |
('-' ) |
|
2075 | 1882 |
('Font...' changeFont ) |
951 | 1883 |
('-' ) |
2448 | 1884 |
('Save As...' save SaveAs ) |
2075 | 1885 |
('Print' doPrint Print ) |
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1886 |
('=' ) |
4487 | 1887 |
('More' more ) |
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1888 |
('Shell' others Ctrl ) |
914 | 1889 |
). |
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1890 |
m := PopUpMenu itemList:items resources:resources. |
4487 | 1891 |
m subMenuAt:#more put:moreMenu. |
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
1892 |
m subMenuAt:#others put:subMenu. |
1347 | 1893 |
|
1894 |
"/ disabled - for now; |
|
1895 |
"/ need a more intelligent filtering of control characters. |
|
1896 |
"/ |
|
1897 |
"/ filterStream isNil ifTrue:[ |
|
1898 |
"/ items := items , #( |
|
1899 |
"/ ('-' ) |
|
2075 | 1900 |
"/ ('Start Save as ...' startSaveAs ) |
1901 |
"/ ('Start Print' startPrint ) |
|
1347 | 1902 |
"/ ) |
1903 |
"/ ] ifFalse:[ |
|
1904 |
"/ items := items , #( |
|
1905 |
"/ ('-' ) |
|
2075 | 1906 |
"/ ('Stop filter' stopFilter ) |
1347 | 1907 |
"/ ) |
1908 |
"/ ]. |
|
914 | 1909 |
]. |
1910 |
||
2810
d57cc02787de
refactored intention revealing code:
Claus Gittinger <cg@exept.de>
parents:
2778
diff
changeset
|
1911 |
self hasSelection ifFalse:[ |
914 | 1912 |
m disable:#copySelection. |
1913 |
]. |
|
1914 |
^ m. |
|
1915 |
||
3225 | 1916 |
"Modified: / 03-04-2007 / 08:58:26 / cg" |
1347 | 1917 |
! |
1918 |
||
4487 | 1919 |
openFileBrowserOnIt |
1920 |
"open a fileBrowser on the selected fileName" |
|
1921 |
||
4836 | 1922 |
|selection fileName| |
4487 | 1923 |
|
4630 | 1924 |
shellDirectory notNil ifTrue:[ |
4836 | 1925 |
selection := self selectionAsString. |
1926 |
fileName := selection asFilename. |
|
1927 |
fileName isAbsolute ifFalse:[ |
|
4837 | 1928 |
fileName := shellDirectory construct:selection. |
4836 | 1929 |
]. |
1930 |
self openFileBrowserOnFileNamed:fileName pathName |
|
4630 | 1931 |
]. |
4487 | 1932 |
! |
1933 |
||
4295 | 1934 |
setGreenDisplayMode |
1935 |
self foregroundColor:Color green backgroundColor:Color black. |
|
1936 |
self cursorForegroundColor:Color black backgroundColor:Color green. |
|
1937 |
! |
|
1938 |
||
1939 |
setNormalDisplayMode |
|
1940 |
self foregroundColor:Color black backgroundColor:Color white. |
|
1941 |
self cursorForegroundColor:Color white backgroundColor:Color black. |
|
1942 |
! |
|
1943 |
||
4300 | 1944 |
setRedDisplayMode |
1945 |
self foregroundColor:(Color white) backgroundColor:(Color red:80). |
|
1946 |
self cursorForegroundColor:(Color red:80) backgroundColor:(Color white). |
|
1947 |
! |
|
1948 |
||
4295 | 1949 |
setReverseDisplayMode |
1950 |
|fg bg| |
|
1951 |
||
1952 |
fg := self foregroundColor. |
|
1953 |
bg := self backgroundColor. |
|
1954 |
self foregroundColor:bg backgroundColor:fg. |
|
1955 |
self cursorForegroundColor:fg backgroundColor:bg. |
|
1956 |
! |
|
1957 |
||
1347 | 1958 |
startSaveAs |
1959 |
"start saving all received data to some file" |
|
1960 |
||
1961 |
|fn| |
|
1962 |
||
1963 |
fn := Dialog requestFileName:'Save received data in file:'. |
|
1964 |
fn size > 0 ifTrue:[ |
|
1965 |
filterStream := fn asFilename writeStream |
|
1966 |
]. |
|
1967 |
||
1968 |
"Created: / 29.4.1999 / 11:06:29 / cg" |
|
1969 |
! |
|
1970 |
||
1971 |
stopFilter |
|
1972 |
"stop saving/printing of received data" |
|
1973 |
||
1974 |
filterStream close. |
|
1975 |
filterStream := nil. |
|
1976 |
||
1977 |
"Created: / 29.4.1999 / 11:07:49 / cg" |
|
1978 |
"Modified: / 29.4.1999 / 11:09:52 / cg" |
|
914 | 1979 |
! ! |
1980 |
||
940 | 1981 |
!TerminalView methodsFor:'misc'! |
914 | 1982 |
|
5008 | 1983 |
debugPrintCharacter:aCharacter as:what |
1984 |
Transcript show:what; show:' <'. |
|
1985 |
aCharacter codePoint < 32 ifTrue:[ |
|
1986 |
Transcript show:'\x'; show:(aCharacter codePoint hexPrintString:2) |
|
1987 |
] ifFalse:[ |
|
1988 |
Transcript show:aCharacter |
|
1989 |
]. |
|
1990 |
Transcript showCR:'>' |
|
1991 |
! |
|
1992 |
||
914 | 1993 |
removeTrailingBlankLines |
1994 |
^ self |
|
1995 |
! ! |
|
1996 |
||
2498 | 1997 |
!TerminalView methodsFor:'processing-input'! |
914 | 1998 |
|
1420 | 1999 |
doNothing |
2000 |
"private - end of an ignored escape-sequence" |
|
2001 |
||
2002 |
self endOfSequence |
|
2003 |
||
2004 |
"Created: / 12.6.1998 / 20:40:43 / cg" |
|
2005 |
! |
|
2006 |
||
2007 |
endOfSequence |
|
2008 |
"private - reset state-machine at end of escape-sequence" |
|
2009 |
||
2010 |
state := 0. |
|
2011 |
||
2012 |
"Created: / 12.6.1998 / 20:39:52 / cg" |
|
2013 |
! |
|
2014 |
||
4446
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2015 |
nextPut:char |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2016 |
"process a character (i.e. the shells output)" |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2017 |
|
4809 | 2018 |
"/ Debug := true |
2019 |
"/ Debug := false |
|
4446
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2020 |
Debug ifTrue:[ |
4809 | 2021 |
Transcript show:state; show:' <'; show:(char codePoint hexPrintString:2); showCR:'>'. |
4446
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2022 |
]. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2023 |
|
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2024 |
(char == Character nl) ifTrue:[ |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2025 |
self endEntry. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2026 |
self doCursorDown:1. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2027 |
^ self endEntry. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2028 |
]. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2029 |
(char == Character return) ifTrue:[ |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2030 |
self endEntry. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2031 |
self cursorToBeginOfLine. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2032 |
^ self. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2033 |
]. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2034 |
(char == Character backspace) ifTrue:[ |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2035 |
self endEntry. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2036 |
self doCursorLeft:1. "/ doBackspace |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2037 |
^ self endEntry. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2038 |
]. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2039 |
(char == Character bell) ifTrue:[ |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2040 |
self beep. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2041 |
^ self |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2042 |
]. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2043 |
char asciiValue < 32 ifTrue:[ |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2044 |
char ~~ Character tab ifTrue:[ |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2045 |
char asciiValue ~~ 0 ifTrue:[ |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2046 |
Debug ifTrue:[ |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2047 |
Transcript show:'unhandled control key: '; showCR:char storeString. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2048 |
]. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2049 |
]. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2050 |
^ self. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2051 |
] |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2052 |
]. |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2053 |
self show:char |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2054 |
|
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2055 |
"Modified: / 21.7.1998 / 20:06:04 / cg" |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2056 |
! |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2057 |
|
1017
8af14b2315fa
care for non-external-stream when window size changes.
Claus Gittinger <cg@exept.de>
parents:
1015
diff
changeset
|
2058 |
nextPutAll:aString |
1021
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2059 |
"/ self processInput:aString n:aString size |
2594 | 2060 |
|
4285 | 2061 |
Debug ifTrue:[ |
2062 |
Transcript |
|
4446
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2063 |
show:(self class name); show:': nextPutAll - state: '; show:state; |
4809 | 2064 |
show:' got: <'. |
2065 |
aString do:[:ch | |
|
2066 |
Transcript show:'<'; show:(ch codePoint hexPrintString:2); show:'>' |
|
2067 |
]. |
|
2068 |
Transcript cr; endEntry. |
|
4285 | 2069 |
]. |
1021
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2070 |
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
|
2071 |
|
8af14b2315fa
care for non-external-stream when window size changes.
Claus Gittinger <cg@exept.de>
parents:
1015
diff
changeset
|
2072 |
"Created: / 27.7.1998 / 15:10:59 / cg" |
1021
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2073 |
"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
|
2074 |
! |
8af14b2315fa
care for non-external-stream when window size changes.
Claus Gittinger <cg@exept.de>
parents:
1015
diff
changeset
|
2075 |
|
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
2076 |
processInput:buffer n:count |
4315 | 2077 |
"actually: output coming from the connected application (aka input to me); |
2078 |
the stuff coming from the application is a mix of plain text and CSI escape sequences. |
|
2079 |
If we process each character individually, things are trivial, but slow. |
|
2080 |
Therefore, we collect big chunks of non-escaped text and buffer them to make |
|
2081 |
use of the inherited buffered output optimizations (see TextCollector). |
|
2082 |
Thus, we collect until an escape sequence is encountered, and flush the buffered stuff then, |
|
2083 |
proceed in single-character mode (processState0:) until the sequence is finished, and continue |
|
2084 |
collecting. |
|
2085 |
This makes this terminalView's speed usable and actually competitive with some existing |
|
4612 | 2086 |
console applications. |
2087 |
BTW: It is *much* faster than the MSWindows command.com window, |
|
2088 |
- so much for the 'slow' Smalltalk ;-)" |
|
4315 | 2089 |
|
997 | 2090 |
|sensor| |
2091 |
||
4315 | 2092 |
"/ remember how much is in the queue... |
2093 |
[ |
|
2094 |
sizeOfOutstandingInputToBeProcessed := sizeOfOutstandingInputToBeProcessed - count. |
|
2095 |
] valueUninterruptably. |
|
4449 | 2096 |
"/ Debug := true |
4450 | 2097 |
"/ Debug := false |
4285 | 2098 |
Debug ifTrue:[ |
4446
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2099 |
Transcript show:self class name; show:': processInput - state: '; show: state; |
02b5fbf621d3
refactored character processing
Claus Gittinger <cg@exept.de>
parents:
4338
diff
changeset
|
2100 |
show:' got: '; showCR: count. |
4285 | 2101 |
]. |
2102 |
||
1347 | 2103 |
filterStream notNil ifTrue:[ |
2104 |
filterStream nextPutAll:(buffer copyTo:count). |
|
2105 |
]. |
|
4267 | 2106 |
"/ '*' print. (buffer copyTo:count) asByteArray hexPrintString printCR. |
1347 | 2107 |
|
1077
49525bbae21c
added #saveCursor / #restoreCursor
Claus Gittinger <cg@exept.de>
parents:
1055
diff
changeset
|
2108 |
"/ self hideCursor. |
997 | 2109 |
|
1015 | 2110 |
"/ the following may not be too clean, but adds a lot of speed. |
2111 |
"/ instead of passing every individual character through the |
|
2112 |
"/ escape-state machine, collect chunks of non-control text |
|
2113 |
"/ when in state 0, and add them immediately to the pendingLines |
|
2114 |
"/ collection of the textCollectors asynchronous update mechanism. |
|
2115 |
"/ This helps a lot if you do something like "ls -lR /" ... |
|
2116 |
"/ For debugging the state machine, reenable the commented lines |
|
2117 |
"/ below. |
|
2118 |
||
2119 |
"/1 to:count do:[:i| |
|
2120 |
"/ self nextPut:(buffer at:i). |
|
2121 |
"/]. |
|
2122 |
"/self showCursor. |
|
2123 |
"/^ self. |
|
2124 |
||
2125 |
access critical:[ |
|
2191 | 2126 |
|index controlCharIndex stringWithOutControl crnlFollows| |
997 | 2127 |
|
2191 | 2128 |
index := 1. |
2129 |
[index <= count] whileTrue:[ |
|
4290 | 2130 |
stringWithOutControl := nil. |
2131 |
||
4321 | 2132 |
(state == 0) ifTrue:[ |
4267 | 2133 |
"/ in initial state: |
1015 | 2134 |
"/ quick scan forward for next control character ... |
2191 | 2135 |
controlCharIndex := buffer indexOfControlCharacterStartingAt:index. |
2136 |
controlCharIndex > count ifTrue:[controlCharIndex := 0]. |
|
1055
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2137 |
|
2191 | 2138 |
controlCharIndex == 0 ifTrue:[ |
1015 | 2139 |
"/ no control characters - simply append all |
4267 | 2140 |
"/ to the outstanding lines... |
2191 | 2141 |
stringWithOutControl := buffer copyFrom:index to:count. |
4267 | 2142 |
crnlFollows := false. |
2191 | 2143 |
index := count + 1. "/ leave loop. |
1015 | 2144 |
] ifFalse:[ |
2191 | 2145 |
controlCharIndex > index ifTrue:[ |
4267 | 2146 |
"/ some more regular character(s) before control character |
2191 | 2147 |
stringWithOutControl := buffer copyFrom:index to:controlCharIndex-1. |
2148 |
index := controlCharIndex. "/ proceed withcontrol character |
|
1015 | 2149 |
crnlFollows := false. |
2191 | 2150 |
index < (count - 1) ifTrue:[ |
2151 |
(buffer at:index) == Character return ifTrue:[ |
|
2152 |
(buffer at:index+1) == Character nl ifTrue:[ |
|
1015 | 2153 |
crnlFollows := true. |
2191 | 2154 |
index := index + 2. |
1015 | 2155 |
] |
997 | 2156 |
] |
1015 | 2157 |
]. |
4267 | 2158 |
] ifFalse:[ |
2159 |
"/ controlchr immediately follows |
|
1015 | 2160 |
] |
2161 |
]. |
|
997 | 2162 |
]. |
2163 |
||
2191 | 2164 |
stringWithOutControl notNil ifTrue:[ |
4614 | 2165 |
doUTF ifTrue:[ |
2166 |
Error handle:[:ex | |
|
2167 |
] do:[ |
|
2168 |
stringWithOutControl := stringWithOutControl utf8Decoded |
|
2169 |
]. |
|
4612 | 2170 |
]. |
2356 | 2171 |
(cursorCol + outstandingLine size + stringWithOutControl size) >= numberOfColumns ifTrue:[ |
4321 | 2172 |
"/ characterwise, for correct wrap handling at line end |
2268 | 2173 |
stringWithOutControl do:[:eachCharacter | |
2174 |
self nextPut:eachCharacter. |
|
4452 | 2175 |
self endEntry. |
2176 |
cursorCol >= numberOfColumns ifTrue:[ |
|
2177 |
self validateCursorCol:cursorCol inLine:cursorLine. |
|
2178 |
]. |
|
2268 | 2179 |
]. |
2356 | 2180 |
crnlFollows ifTrue:[ |
2181 |
self nextPut:Character return. |
|
2182 |
self nextPut:Character nl. |
|
2183 |
]. |
|
2184 |
self endEntry. |
|
997 | 2185 |
] ifFalse:[ |
2356 | 2186 |
|
2187 |
Debug ifTrue:[ |
|
2188 |
Transcript showCR:'String:<', stringWithOutControl, '>'. |
|
4809 | 2189 |
stringWithOutControl do:[:ch | |
4811 | 2190 |
"/ ch codePoint > 255 ifTrue:[self halt]. |
4809 | 2191 |
Transcript show:'<'; show:(ch codePoint hexPrintString:2); show:'>' |
2192 |
]. |
|
2193 |
Transcript cr. |
|
2356 | 2194 |
]. |
2195 |
currentEmphasis notNil ifTrue:[ |
|
2196 |
stringWithOutControl := stringWithOutControl emphasizeAllWith:currentEmphasis |
|
2197 |
]. |
|
2198 |
||
4449 | 2199 |
access critical:[ |
2200 |
outstandingLine size > 0 ifTrue:[ |
|
2201 |
outstandingLine := outstandingLine , stringWithOutControl. |
|
2202 |
] ifFalse:[ |
|
2203 |
outstandingLine := stringWithOutControl. |
|
2204 |
]. |
|
2205 |
crnlFollows ifTrue:[ |
|
2206 |
"/ 'xp' printCR. |
|
2207 |
outstandingLines isNil ifTrue:[ |
|
2208 |
outstandingLines := OrderedCollection with:outstandingLine |
|
2209 |
] ifFalse:[ |
|
2210 |
outstandingLines add:outstandingLine. |
|
2211 |
]. |
|
2212 |
outstandingLine := ''. |
|
2213 |
]. |
|
1015 | 2214 |
]. |
4321 | 2215 |
"/ collecting ifTrue:[ |
2216 |
"/ flushPending ifFalse:[ |
|
2217 |
"/ self installDelayedUpdate |
|
2218 |
"/ ] ifTrue:[ |
|
2219 |
"/ "/ outstandingLines size > collectSize ifTrue:[ |
|
2220 |
"/ "/ self endEntry |
|
2221 |
"/ "/ ] |
|
2222 |
"/ ] |
|
2223 |
"/ ] ifFalse:[ |
|
2224 |
"/ self endEntry |
|
2225 |
"/ ]. |
|
1015 | 2226 |
]. |
997 | 2227 |
] ifFalse:[ |
1015 | 2228 |
"/ no chunk to append (in an escape sequence) |
2229 |
"/ must handle individual characters |
|
2230 |
"/ 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
|
2231 |
|
4290 | 2232 |
"/ self endEntry. |
2207 | 2233 |
self nextPut:(buffer at:index). |
2191 | 2234 |
index := index + 1. |
2235 |
[state ~~ 0 and:[index <= count]] whileTrue:[ |
|
2207 | 2236 |
self nextPut:(buffer at:index). |
2191 | 2237 |
index := index + 1. |
1055
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2238 |
] |
1015 | 2239 |
] |
2240 |
]. |
|
4321 | 2241 |
"/ inFlush := false. |
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
2242 |
]. |
948 | 2243 |
|
4321 | 2244 |
(state == 0 and:[self shown]) ifTrue:[ |
1055
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2245 |
(sensor := self sensor) notNil ifTrue:[ |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2246 |
"/ 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
|
2247 |
"/ enforce update of the view (asynchronous) |
997 | 2248 |
|
1055
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2249 |
(sensor hasEvent:#processInput:n: for:self) ifFalse:[ |
997 | 2250 |
self endEntry. |
2251 |
self showCursor. |
|
1055
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2252 |
"/ self makeCursorVisible. |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2253 |
] ifTrue:[ |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2254 |
"/ 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
|
2255 |
"/ 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
|
2256 |
"/ 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
|
2257 |
"/ 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
|
2258 |
"/ collectSize lines. |
1015 | 2259 |
|
1055
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2260 |
outstandingLines size > collectSize ifTrue:[ |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2261 |
self endEntry. |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2262 |
self showCursor. |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2263 |
|
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2264 |
"/ 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
|
2265 |
windowGroup notNil ifTrue:[ |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2266 |
windowGroup processRealExposeEventsFor:self. |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2267 |
] |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2268 |
]. |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2269 |
] |
eebff36e25e9
stay in slow-loop, while state ~~ 0 (in processInput:).
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
2270 |
]. |
933
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
2271 |
]. |
de456e07697e
much better asynchronous display
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
2272 |
|
4315 | 2273 |
"Created: / 10-06-1998 / 17:26:09 / cg" |
2274 |
"Modified: / 28-01-2002 / 20:41:36 / micha" |
|
2275 |
"Modified: / 30-07-2013 / 10:47:19 / cg" |
|
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
2276 |
! |
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
2277 |
|
1021
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2278 |
sync |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2279 |
self waitForOutputToDrain |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2280 |
|
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2281 |
"Created: / 27.7.1998 / 23:49:44 / cg" |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2282 |
! |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2283 |
|
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2284 |
waitForOutputToDrain |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2285 |
|sensor| |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2286 |
|
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2287 |
sensor := self sensor. |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
2288 |
(sensor notNil and:[sensor userEventCount > 30]) ifTrue:[ |
1323 | 2289 |
[sensor userEventCount > 5] whileTrue:[ |
1021
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2290 |
"/ give terminalView a chance to |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2291 |
"/ catch up. |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2292 |
Delay waitForSeconds:0.1. |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2293 |
] |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2294 |
]. |
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2295 |
|
c3963e925eb5
added #sync; better asynchronous display.
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
2296 |
"Created: / 27.7.1998 / 23:47:22 / cg" |
1363
7297da8a2e02
dont flush input when shell has terminated
Claus Gittinger <cg@exept.de>
parents:
1360
diff
changeset
|
2297 |
"Modified: / 5.5.1999 / 18:51:00 / cg" |
914 | 2298 |
! ! |
2299 |
||
2300 |
!TerminalView methodsFor:'queries'! |
|
2301 |
||
4718 | 2302 |
isKeyboardConsumer |
2303 |
"return true, if the receiver is a keyboard consumer; |
|
2304 |
Always return true here" |
|
2305 |
||
2306 |
^ true |
|
2307 |
! |
|
2308 |
||
914 | 2309 |
preferredExtent |
1420 | 2310 |
"return my preferred extent - this is computed from my numberOfLines, |
2311 |
numberOfCols and font size" |
|
2312 |
||
2268 | 2313 |
^ (fontWidth * self class defaultNumberOfColumns + (leftMargin + margin * 2)) |
951 | 2314 |
@ |
1317
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
2315 |
((self heightForLines:self class defaultNumberOfLines) + 8) |
926 | 2316 |
|
979 | 2317 |
"Modified: / 20.6.1998 / 20:06:57 / cg" |
929 | 2318 |
! |
2319 |
||
2320 |
terminalType |
|
1420 | 2321 |
"returns a string describing this terminal (usually, this is |
2322 |
passed down to the shell as TERM environment variable). |
|
2323 |
Here, 'dump' is returned." |
|
2324 |
||
1354
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
2325 |
^ 'dump' |
929 | 2326 |
|
2327 |
"Created: / 10.6.1998 / 16:22:30 / cg" |
|
1354
94e7e8be960f
must keep track of nLines/nCols in sizeChange (even if not unix)
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
2328 |
"Modified: / 5.5.1999 / 11:22:32 / cg" |
914 | 2329 |
! ! |
2330 |
||
4265 | 2331 |
!TerminalView methodsFor:'reader process'! |
2332 |
||
4315 | 2333 |
readAnyAvailableData |
2334 |
"read data from the stream, |
|
2335 |
and sends me #processInput:n: events if something arrived. |
|
2336 |
Returns the amount of data read." |
|
2337 |
||
2338 |
|buffer n bufferSize| |
|
2339 |
||
2340 |
outStream isNil ifTrue:[^ 0]. |
|
2341 |
||
2342 |
"/ avoid too many processInput messages to be in the buffer, |
|
2343 |
"/ otherwise, the reaction on ctrl-s/ctrl-c is too slow, as |
|
2344 |
"/ many processInput messages are in the sensor's queue before the keypress |
|
2345 |
"/ event. We need another queue, actually so the sensor's keypress events |
|
2346 |
"/ are not blocked while reading a lot of input. |
|
2347 |
[sizeOfOutstandingInputToBeProcessed > 4096] whileTrue:[ |
|
2348 |
Delay waitForSeconds:0.1 |
|
2349 |
]. |
|
2350 |
||
4641 | 2351 |
bufferSize := 1024*2. |
4315 | 2352 |
|
2353 |
buffer := String new:bufferSize. |
|
2354 |
ExternalStream readErrorSignal handle:[:ex | |
|
2355 |
n := 0 |
|
2356 |
] do:[ |
|
2357 |
n := outStream nextAvailableBytes:bufferSize into:buffer startingAt:1. |
|
2358 |
]. |
|
2359 |
n > 0 ifTrue:[ |
|
4641 | 2360 |
ignoreOutput ifFalse:[ |
2361 |
"/ Transcript showCR:n. |
|
2362 |
self pushEvent:#processInput:n: with:buffer with:n. |
|
2363 |
"/ remember how much is in the queue... |
|
2364 |
[ |
|
2365 |
sizeOfOutstandingInputToBeProcessed := sizeOfOutstandingInputToBeProcessed + n. |
|
2366 |
] valueUninterruptably |
|
2367 |
]. |
|
4315 | 2368 |
]. |
2369 |
||
2370 |
^ n |
|
2371 |
||
2372 |
"Created: / 05-05-1999 / 17:57:39 / cg" |
|
2373 |
"Modified: / 28-01-2002 / 21:10:25 / micha" |
|
2374 |
"Modified (comment): / 30-07-2013 / 10:50:03 / cg" |
|
2375 |
! |
|
2376 |
||
4265 | 2377 |
readerProcessLoop |
4777 | 2378 |
"look for the command's output, |
4265 | 2379 |
and send me #processInput:n: events whenever something arrives." |
2380 |
||
2381 |
StreamError handle:[:ex | |
|
2382 |
Transcript show:'Terminal(PTY-reader) [error]: '; showCR:ex description. |
|
2383 |
] do:[ |
|
2384 |
[true] whileTrue:[ |
|
2385 |
AbortOperationRequest handle:[:ex | |
|
2386 |
self showCursor. |
|
4457 | 2387 |
(outStream isNil or:[outStream atEnd]) ifTrue:[ ex reject ]. |
4265 | 2388 |
] do:[ |
2389 |
|n sensor| |
|
2390 |
||
4612 | 2391 |
"/ Delay waitForSeconds:0.01. |
4265 | 2392 |
outStream readWait. |
2393 |
sensor := self sensor. |
|
2394 |
(sensor notNil and:[sensor hasKeyPressEventFor:self]) ifTrue:[ |
|
2395 |
true "(sensor userEventCount > 10)" ifTrue:[ |
|
2396 |
"/ give terminalView a chance to |
|
2397 |
"/ send out the character. |
|
4321 | 2398 |
"/ Transcript showCR:'d'. |
4265 | 2399 |
Delay waitForSeconds:0.01. |
2400 |
] |
|
2401 |
] ifFalse:[ |
|
2402 |
n := self readAnyAvailableData. |
|
2403 |
n > 0 ifTrue:[ |
|
2404 |
shellPid notNil ifTrue:[ |
|
2405 |
self waitForOutputToDrain. |
|
2406 |
] |
|
2407 |
] ifFalse:[ |
|
2408 |
n == 0 ifTrue:[ |
|
2409 |
"/ Windows IPC has a bug - it always |
|
2410 |
"/ returns 0 (when the command is idle) |
|
4612 | 2411 |
"/ and says it's at the end (sigh) |
4265 | 2412 |
|
2413 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
2414 |
Delay waitForSeconds:0.01 |
|
2415 |
] ifFalse:[ |
|
2416 |
outStream atEnd ifTrue:[ |
|
4327 | 2417 |
self closeStreams. |
4265 | 2418 |
Processor activeProcess terminate. |
2419 |
] ifFalse:[ |
|
2420 |
"/ this should not happen. |
|
2421 |
Delay waitForSeconds:0.05 |
|
2422 |
] |
|
2423 |
]. |
|
2424 |
] |
|
2425 |
] |
|
2426 |
] |
|
2427 |
] |
|
2428 |
] |
|
2429 |
] |
|
4315 | 2430 |
|
2431 |
"Modified: / 30-07-2013 / 10:30:38 / cg" |
|
4265 | 2432 |
! |
2433 |
||
2434 |
startReaderProcess |
|
2435 |
"Start a reader process, which looks for the commands output, |
|
2436 |
and sends me #processInput:n: events whenever something arrives." |
|
2437 |
||
2438 |
self obsoleteMethodWarning. |
|
2439 |
self startReaderProcessWhenVisible. |
|
2440 |
||
2441 |
" |
|
2442 |
VT100TerminalView openShell |
|
2443 |
" |
|
2444 |
||
2445 |
"Modified: / 5.5.1999 / 17:58:02 / cg" |
|
2446 |
"Modified: / 28.1.2002 / 21:10:13 / micha" |
|
2447 |
! |
|
2448 |
||
2449 |
startReaderProcessNow |
|
2450 |
"Start a reader process, which looks for the commands output, |
|
2451 |
and sends me #processInput:n: events whenever something arrives." |
|
2452 |
||
4612 | 2453 |
self startReaderProcessWhenVisible:false |
4265 | 2454 |
|
2455 |
" |
|
2456 |
VT100TerminalView openShell |
|
2457 |
" |
|
2458 |
||
2459 |
"Modified: / 5.5.1999 / 17:58:02 / cg" |
|
2460 |
"Modified: / 28.1.2002 / 21:10:13 / micha" |
|
2461 |
! |
|
2462 |
||
2463 |
startReaderProcessWhenVisible |
|
2464 |
"Start a reader process, which looks for the commands output, |
|
2465 |
and sends me #processInput:n: events whenever something arrives." |
|
2466 |
||
4612 | 2467 |
self startReaderProcessWhenVisible:true |
2468 |
||
2469 |
" |
|
2470 |
VT100TerminalView openShell |
|
2471 |
" |
|
2472 |
||
2473 |
"Modified: / 5.5.1999 / 17:58:02 / cg" |
|
2474 |
"Modified: / 28.1.2002 / 21:10:13 / micha" |
|
2475 |
! |
|
2476 |
||
2477 |
startReaderProcessWhenVisible:whenVisible |
|
2478 |
"Start a reader process, which looks for the commands output, |
|
2479 |
and sends me #processInput:n: events whenever something arrives." |
|
2480 |
||
4265 | 2481 |
readerProcess isNil ifTrue:[ |
2482 |
readerProcess := [ |
|
2483 |
[ |
|
4612 | 2484 |
whenVisible ifTrue:[self waitUntilVisible]. |
4265 | 2485 |
self readerProcessLoop. |
2486 |
] ifCurtailed:[ |
|
2487 |
readerProcess := nil |
|
2488 |
] |
|
2489 |
] fork. "/ forkAt:9. |
|
2490 |
readerProcess name:'pty reader'. |
|
2491 |
] |
|
2492 |
||
2493 |
" |
|
2494 |
VT100TerminalView openShell |
|
2495 |
" |
|
2496 |
||
2497 |
"Modified: / 5.5.1999 / 17:58:02 / cg" |
|
2498 |
"Modified: / 28.1.2002 / 21:10:13 / micha" |
|
2499 |
! |
|
2500 |
||
2501 |
stopReaderProcess |
|
2502 |
"stop the background reader thread" |
|
2503 |
||
2504 |
|sensor| |
|
2505 |
||
2506 |
readerProcess notNil ifTrue:[ |
|
2507 |
readerProcess terminate. |
|
2508 |
"/ give it a chance to really terminate |
|
2509 |
Processor yield. |
|
2510 |
readerProcess := nil |
|
2511 |
]. |
|
2512 |
||
2513 |
"/ flush any leftover input-processing events |
|
2514 |
(sensor := self sensor) notNil ifTrue:[ |
|
2515 |
sensor flushEventsFor:self withType:#processInput:n:. |
|
2516 |
] |
|
2517 |
"Modified: / 21.7.1998 / 19:00:13 / cg" |
|
2518 |
! ! |
|
2519 |
||
2506 | 2520 |
!TerminalView methodsFor:'searching'! |
2521 |
||
2522 |
startPositionForSearchBackward |
|
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
2523 |
^ self startPositionForSearchBackwardBasedOnSelection |
2506 | 2524 |
! |
2525 |
||
2526 |
startPositionForSearchForward |
|
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
2527 |
^ self startPositionForSearchForwardBasedOnSelection |
2506 | 2528 |
! ! |
2529 |
||
914 | 2530 |
!TerminalView methodsFor:'selection handling'! |
2531 |
||
1317
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
2532 |
autoMoveCursorToEndOfSelection |
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
2533 |
"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
|
2534 |
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
|
2535 |
|
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
2536 |
^ false |
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
2537 |
|
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
2538 |
! |
dace272367a7
do not move the cursor when double-clicking for a selection.
Claus Gittinger <cg@exept.de>
parents:
1316
diff
changeset
|
2539 |
|
914 | 2540 |
paste:someText |
2541 |
"paste - redefined to send the chars to the shell instead |
|
2542 |
of pasting into the view" |
|
2543 |
||
950 | 2544 |
|s nLines| |
2545 |
||
2573
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
2546 |
inStream isNil ifTrue:[ |
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
2547 |
self flash. |
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
2548 |
^ self "/ already closed |
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
2549 |
]. |
9ef4727d2a57
menu changes (goto does not make sense);
Claus Gittinger <cg@exept.de>
parents:
2539
diff
changeset
|
2550 |
|
950 | 2551 |
s := someText. |
2552 |
s isString ifTrue:[ |
|
2553 |
s := s asStringCollection |
|
2554 |
] ifFalse:[ |
|
2555 |
(s isKindOf:StringCollection) ifFalse:[ |
|
2556 |
self warn:'selection (' , s class name , ') is not convertable to Text'. |
|
2557 |
^ self |
|
2558 |
] |
|
2559 |
]. |
|
2560 |
(nLines := s size) == 0 ifTrue:[^ self]. |
|
2561 |
(nLines == 1 and:[(s at:1) size == 0]) ifTrue:[^ self]. |
|
4285 | 2562 |
|
950 | 2563 |
s keysAndValuesDo:[:idx :line | |
4285 | 2564 |
line notNil ifTrue:[ |
5008 | 2565 |
(Debug or:[DebugKeyboard]) ifTrue:[ |
4285 | 2566 |
Transcript showCR:'send paste line: ',line asByteArray hexPrintString |
2567 |
]. |
|
2568 |
]. |
|
4601 | 2569 |
self shouldProcessInputInLineEditMode ifTrue:[ |
2570 |
line do:[:ch | self keyPressInLineEditMode:ch ]. |
|
2571 |
idx ~~ nLines ifTrue:[ |
|
2572 |
self keyPressInLineEditMode:#Return |
|
2573 |
] |
|
4317 | 2574 |
] ifFalse:[ |
4601 | 2575 |
self send:line. |
2576 |
idx ~~ nLines ifTrue:[ |
|
2577 |
self sendLineEnd |
|
2578 |
] |
|
950 | 2579 |
] |
2580 |
]. |
|
2581 |
||
2582 |
"Modified: / 12.6.1998 / 22:12:47 / cg" |
|
4490 | 2583 |
! |
2584 |
||
2585 |
selection |
|
2586 |
|sel| |
|
2587 |
||
2588 |
sel := super selection. |
|
4492 | 2589 |
sel isNil ifTrue:[^ sel]. |
4490 | 2590 |
|
2591 |
"/ if it is a line-wise collection, return multiple lines; |
|
2592 |
"/ otherwise, concatenate to make it one long string. |
|
2593 |
"/ this allows for multi-line commands (many args) to be copy-pasted easily |
|
2594 |
selectionStartCol == 1 ifTrue:[ |
|
2595 |
selectionEndCol == 0 ifTrue:[ |
|
2596 |
^ sel "/ a full-line (3xclick selection) |
|
2597 |
]. |
|
2598 |
]. |
|
2599 |
^ StringCollection with:(sel asStringWith:''). |
|
914 | 2600 |
! ! |
2601 |
||
4604 | 2602 |
!TerminalView methodsFor:'sending'! |
2603 |
||
2604 |
send:aString |
|
2605 |
"send aString to the underlying program's stdinput" |
|
2606 |
||
2607 |
aString notEmptyOrNil ifTrue:[ |
|
4809 | 2608 |
aString containsNon7BitAscii ifTrue:[ |
2609 |
aString do:[:each | |
|
2610 |
self sendCharacter:each |
|
2611 |
]. |
|
2612 |
] ifFalse:[ |
|
2613 |
recorderStream notNil ifTrue:[ |
|
2614 |
recorderStream nextPutAll:aString |
|
2615 |
]. |
|
5008 | 2616 |
(Debug or:[DebugKeyboard]) ifTrue:[ |
4809 | 2617 |
Transcript showCR:'send <',aString,'>' |
2618 |
]. |
|
2619 |
inStream nextPutAll:aString |
|
4604 | 2620 |
]. |
2621 |
]. |
|
2622 |
||
2623 |
"Created: / 29-07-2013 / 18:18:24 / cg" |
|
2624 |
! |
|
2625 |
||
2626 |
sendCR:aString |
|
2627 |
"send aString followed by a return to the underlying program's stdinput" |
|
2628 |
||
2629 |
self send:aString. |
|
4983 | 2630 |
self sendLineEnd. |
4604 | 2631 |
! |
2632 |
||
2633 |
sendCharacter:aCharacter |
|
4809 | 2634 |
"send a single character to the underlying program's stdin" |
4604 | 2635 |
|
5008 | 2636 |
aCharacter codePoint > 16r7F ifTrue:[ |
2637 |
inputIsUTF8 ifTrue:[ |
|
2638 |
aCharacter utf8Encoded do:[:eachUTFChar| |
|
2639 |
(Debug or:[DebugKeyboard]) ifTrue:[ |
|
2640 |
self debugPrintCharacter:eachUTFChar as:'send utf'. |
|
2641 |
]. |
|
2642 |
recorderStream notNil ifTrue:[ |
|
2643 |
recorderStream nextPut:eachUTFChar |
|
2644 |
]. |
|
2645 |
inStream nextPut:eachUTFChar. |
|
4809 | 2646 |
]. |
5008 | 2647 |
^ self |
2648 |
]. |
|
2649 |
aCharacter bitsPerCharacter > 8 ifTrue:[ |
|
4809 | 2650 |
"/ ignore |
2651 |
Transcript showCR:(self class name,': invalid (non-8bit) character ignored'). |
|
5008 | 2652 |
^ self |
4809 | 2653 |
]. |
5008 | 2654 |
"/ send normal |
4604 | 2655 |
]. |
2656 |
||
2657 |
recorderStream notNil ifTrue:[ |
|
2658 |
recorderStream nextPut:aCharacter |
|
2659 |
]. |
|
5008 | 2660 |
(Debug or:[DebugKeyboard]) ifTrue:[ |
2661 |
self debugPrintCharacter:aCharacter as:'send'. |
|
4604 | 2662 |
]. |
2663 |
||
2664 |
inStream nextPut:aCharacter. |
|
2665 |
||
2666 |
"Created: / 29-07-2013 / 18:18:24 / cg" |
|
2667 |
! |
|
2668 |
||
2669 |
sendLine:aString |
|
5008 | 2670 |
(Debug or:[DebugKeyboard]) ifTrue:[ |
4604 | 2671 |
'VT100: sendline: ' print. aString asByteArray hexPrintString printCR |
2672 |
]. |
|
2673 |
||
2674 |
self send:aString. |
|
2675 |
self sendLineEnd |
|
2676 |
! |
|
2677 |
||
2678 |
sendLineEnd |
|
4983 | 2679 |
inputTranslateCRToNL ifTrue:[ |
2680 |
self sendCharacter:(Character nl). |
|
4604 | 2681 |
] ifFalse:[ |
4983 | 2682 |
inputTranslateCRToCRNL ifTrue:[ |
2683 |
self send:(String crlf). |
|
2684 |
] ifFalse:[ |
|
2685 |
self sendCharacter:(Character return). |
|
2686 |
] |
|
2687 |
] |
|
2688 |
"/ OperatingSystem isMSDOSlike ifTrue:[ |
|
2689 |
"/ self send:String crlf. |
|
2690 |
"/ ] ifFalse:[ |
|
2691 |
"/ self send:String return. |
|
2692 |
"/ ]. |
|
4604 | 2693 |
! ! |
2694 |
||
914 | 2695 |
!TerminalView class methodsFor:'documentation'! |
2696 |
||
2697 |
version |
|
4799 | 2698 |
^ '$Header$' |
3758 | 2699 |
! |
2700 |
||
2701 |
version_CVS |
|
4799 | 2702 |
^ '$Header$' |
914 | 2703 |
! ! |
2205 | 2704 |
|
4164 | 2705 |
|
2205 | 2706 |
TerminalView initialize! |