--- a/TerminalView.st Sat Apr 02 17:17:00 2016 +0200
+++ b/TerminalView.st Sun Apr 03 14:15:28 2016 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1998 by eXept Software AG
All Rights Reserved
@@ -25,7 +27,8 @@
lineEditMode lineBuffer lineBufferCursorPosition
lineBufferHistory lineBufferHistoryPosition maxHistorySize doUTF
ignoreOutput sendControlKeys
- lastSelectedLineBufferHistoryPosition'
+ lastSelectedLineBufferHistoryPosition inputIsUTF8 outputIsUTF8
+ signalControlKeys'
classVariableNames:'Debug DebugKeyboard DefaultMaxHistorySize'
poolDictionaries:''
category:'Views-TerminalViews'
@@ -92,8 +95,13 @@
lineEditMode if on, do readLine-alike input history and editong
+ signalControlKeys if on, CTRL-C sends an interrupt (for Windows)
+
[class variables]:
Debug := true trace incoming characters
+ Debug := false
+ DebugKeyboard := true trace outgoing characters
+ DebugKeyboard := false
[start with:]
@@ -545,6 +553,20 @@
sendControlKeys := aBoolean
!
+signalControlKeys
+ "if true (default on Windows), CTRL-C sends an interrupt to
+ the program. Otherwise, it is sent as a character (0x03)"
+
+ ^ signalControlKeys
+!
+
+signalControlKeys:aBoolean
+ "if true (default on Windows), CTRL-C sends an interrupt to
+ the program. Otherwise, it is sent as a character (0x03)"
+
+ signalControlKeys := aBoolean
+!
+
translateNLToCRNL
^ translateNLToCRNL
@@ -847,14 +869,17 @@
shortCut := device keyboardMap at:aKey ifAbsent:nil.
(shortCut notNil and:[shortCut isSymbol]) ifTrue:[
(sendControlKeys not or:[ self hasSelection or:[ shortCut == #Paste] ]) ifTrue:[
+ DebugKeyboard ifTrue:[
+ Transcript showCR:'internal handling'.
+ ].
^ super keyPress:shortCut x:x y:y
- ].
+ ].
].
seq := kbdSequences at:rawKey ifAbsent:nil.
seq notNil ifTrue:[
DebugKeyboard ifTrue:[
- Transcript show:'->' ; showCR:seq storeString.
+ Transcript show:'seq ->' ; showCR:seq storeString.
].
self send:(seq withoutCEscapes).
^ self
@@ -866,7 +891,11 @@
rest := rest at:1.
(rest asLowercase between:$a and:$z) ifTrue:[
DebugKeyboard ifTrue:[
- Transcript show:'->' ; showCR:(Character controlCharacter:rest) storeString.
+ Transcript show:'ctrl ->' ; showCR:(Character controlCharacter:rest) storeString.
+ ].
+ (signalControlKeys and:[rawKey == #Ctrlc]) ifTrue:[
+ self doSendInterrupt.
+ ^ self.
].
self sendCharacter:(Character controlCharacter:rest).
^ self
@@ -874,24 +903,25 @@
]
].
- (rawKey startsWith:'Control') ifTrue:[
- ^ self
- ].
- (rawKey startsWith:'Shift') ifTrue:[
- ^ self
- ].
- (rawKey startsWith:'Alt') ifTrue:[
+ ((rawKey startsWith:'Control')
+ or:[ (rawKey startsWith:'Shift')
+ or:[ (rawKey startsWith:'Alt')
+ or:[ (rawKey = 'Ctrl')
+ ]]]) ifTrue:[
+ DebugKeyboard ifTrue:[
+ Transcript showCR:'modifier ignored'.
+ ].
^ self
].
(rawKey startsWith:'Cmd') ifTrue:[
+ DebugKeyboard ifTrue:[
+ Transcript showCR:'CMD handled internal'.
+ ].
^ super keyPress:aKey x:x y:y
].
- (rawKey = 'Ctrl') ifTrue:[
- ^ self
- ].
DebugKeyboard ifTrue:[
- Transcript show:'unhandled key: '; showCR:rawKey.
+ Transcript show:'unhandled: '; showCR:rawKey.
].
"
@@ -1417,6 +1447,7 @@
super initialize.
sendControlKeys := true.
+ signalControlKeys := OperatingSystem isMSWINDOWSlike.
showMatchingParenthesis := false.
self insertMode: false.
alwaysAppendAtEnd := false.
@@ -1428,6 +1459,8 @@
inputTranslateCRToNL := false.
inputTranslateCRToCRNL := OperatingSystem isMSWINDOWSlike.
inputTranslateBackspaceToDelete := false.
+ inputIsUTF8 := UserPreferences current terminalInputIsUTF8.
+ outputIsUTF8 := false. "/ currently unused.
autoWrapFlag := true.
noColors := false.
doUTF := UserPreferences current terminalOutputIsUTF8.
@@ -1777,6 +1810,10 @@
|status|
+ DebugKeyboard ifTrue:[
+ Transcript showCR:'interrupt!!'.
+ ].
+
shellPid notNil ifTrue:[
OperatingSystem isUNIXlike ifTrue:[
OperatingSystem interruptProcessGroup:shellPid.
@@ -1785,6 +1822,8 @@
] ifFalse:[
self warn:'unimplemented for DOS'
]
+ ] ifFalse:[
+ 'VT100: no shell' infoPrintCR.
].
"Modified: / 10.6.1998 / 17:49:49 / cg"
@@ -1795,6 +1834,9 @@
|status|
+ DebugKeyboard ifTrue:[
+ Transcript showCR:'kill!!'.
+ ].
shellPid notNil ifTrue:[
OperatingSystem isUNIXlike ifTrue:[
OperatingSystem killProcessGroup:shellPid.
@@ -1803,6 +1845,8 @@
] ifFalse:[
self warn:'unimplemented for DOS'
]
+ ] ifFalse:[
+ 'VT100: no shell' infoPrintCR.
]
!
@@ -1938,6 +1982,16 @@
!TerminalView methodsFor:'misc'!
+debugPrintCharacter:aCharacter as:what
+ Transcript show:what; show:' <'.
+ aCharacter codePoint < 32 ifTrue:[
+ Transcript show:'\x'; show:(aCharacter codePoint hexPrintString:2)
+ ] ifFalse:[
+ Transcript show:aCharacter
+ ].
+ Transcript showCR:'>'
+!
+
removeTrailingBlankLines
^ self
! !
@@ -2510,7 +2564,7 @@
s keysAndValuesDo:[:idx :line |
line notNil ifTrue:[
- Debug ifTrue:[
+ (Debug or:[DebugKeyboard]) ifTrue:[
Transcript showCR:'send paste line: ',line asByteArray hexPrintString
].
].
@@ -2561,7 +2615,7 @@
recorderStream notNil ifTrue:[
recorderStream nextPutAll:aString
].
- Debug == true ifTrue:[
+ (Debug or:[DebugKeyboard]) ifTrue:[
Transcript showCR:'send <',aString,'>'
].
inStream nextPutAll:aString
@@ -2581,23 +2635,32 @@
sendCharacter:aCharacter
"send a single character to the underlying program's stdin"
- aCharacter bitsPerCharacter > 8 ifTrue:[
- UserPreferences current terminalInputIsUTF8 ifTrue:[
- aCharacter asString utf8Encoded do:[:each8BitChar|
- inStream nextPut:each8BitChar.
+ aCharacter codePoint > 16r7F ifTrue:[
+ inputIsUTF8 ifTrue:[
+ aCharacter utf8Encoded do:[:eachUTFChar|
+ (Debug or:[DebugKeyboard]) ifTrue:[
+ self debugPrintCharacter:eachUTFChar as:'send utf'.
+ ].
+ recorderStream notNil ifTrue:[
+ recorderStream nextPut:eachUTFChar
+ ].
+ inStream nextPut:eachUTFChar.
].
- ] ifFalse:[
+ ^ self
+ ].
+ aCharacter bitsPerCharacter > 8 ifTrue:[
"/ ignore
Transcript showCR:(self class name,': invalid (non-8bit) character ignored').
+ ^ self
].
- ^ self
+ "/ send normal
].
recorderStream notNil ifTrue:[
recorderStream nextPut:aCharacter
].
- Debug == true ifTrue:[
- Transcript showCR:'send <',aCharacter,'>'
+ (Debug or:[DebugKeyboard]) ifTrue:[
+ self debugPrintCharacter:aCharacter as:'send'.
].
inStream nextPut:aCharacter.
@@ -2606,7 +2669,7 @@
!
sendLine:aString
- Debug ifTrue:[
+ (Debug or:[DebugKeyboard]) ifTrue:[
'VT100: sendline: ' print. aString asByteArray hexPrintString printCR
].