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