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