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