--- a/TerminalSession.st Sun Jul 07 09:39:35 2013 +0200
+++ b/TerminalSession.st Sun Jul 07 13:31:18 2013 +0200
@@ -3,7 +3,8 @@
Object subclass:#TerminalSession
instanceVariableNames:'inStream outStream errStream readerProcess shellPid shellCommand
shellDirectory readerDelay pluggableCheckBeforeReadAction
- pluggableProcessInputAction'
+ pluggableProcessInputAction execFDArray stxToStdinPipe
+ stdOutToStxPipe pty'
classVariableNames:'Debug'
poolDictionaries:''
category:'Views-TerminalViews'
@@ -114,6 +115,54 @@
].
!
+createTerminalConnectionAndSetupWith:setupBlock
+ "create a terminal conenction (pseudo terminal or pipe)"
+
+ |slaveFD|
+
+ OperatingSystem isMSWINDOWSlike ifTrue:[
+ "use two pipes to COMMAND.COM"
+ stxToStdinPipe := NonPositionableExternalStream makePipe.
+ stxToStdinPipe isNil ifTrue:[
+ self error:(self class classResources string:'Could not create pipe to COMMAND.COM.') mayProceed:true.
+ ^ self.
+ ].
+
+ stdOutToStxPipe := NonPositionableExternalStream makePipe.
+ stdOutToStxPipe isNil ifTrue:[
+ self error:(self class classResources classResources string:'Could not create pipe from COMMAND.COM.') mayProceed:true.
+ ^ self.
+ ].
+
+ "/ pipe readSide is p at:1;
+ "/ writeSide is p at:2
+
+ slaveFD := (stdOutToStxPipe at:2) fileDescriptor.
+ execFDArray := Array
+ with:(stxToStdinPipe at:1) fileDescriptor "stdin"
+ with:slaveFD "stdout"
+ with:slaveFD. "stderr"
+
+ outStream := stdOutToStxPipe at:1.
+ inStream := stxToStdinPipe at:2.
+ ] ifFalse:[
+ "Use a pseudo-tty"
+ pty := NonPositionableExternalStream makePTYPair.
+ pty isNil ifTrue:[
+ self warn:'Cannot open pty.'.
+ ^ self.
+ ].
+
+ "/ pty at:1 is the master;
+ "/ pty at:2 is the slave
+ inStream := outStream := (pty at:1).
+ setupBlock value.
+ "/ fork a shell process on the slave-side
+ slaveFD := (pty at:2) fileDescriptor.
+ execFDArray := Array with:slaveFD with:slaveFD with:slaveFD.
+ ].
+!
+
killShell
"shut down my shell process and stop the background reader thread."
@@ -149,57 +198,18 @@
Also fork a reader process, to read the shell's output and
tell me, whenever something arrives"
- |pty slaveFD execFdArray blocked exitStatus
- stxToStdinPipe stdOutToStxPipe cmd shell args env shellAndArgs|
+ |blocked exitStatus
+ cmd shell args env shellAndArgs|
shellCommand := aCommand.
shellDirectory := aDirectory.
+ self createTerminalConnectionAndSetupWith:setupBlock.
OperatingSystem isMSWINDOWSlike ifTrue:[
- "use two pipes to COMMAND.COM"
- stxToStdinPipe := NonPositionableExternalStream makePipe.
- stxToStdinPipe isNil ifTrue:[
- self warn:(self class classResources string:'Could not create pipe to COMMAND.COM.').
- ^ self.
- ].
-
- stdOutToStxPipe := NonPositionableExternalStream makePipe.
- stdOutToStxPipe isNil ifTrue:[
- self warn:(self class classResources classResources string:'Could not create pipe from COMMAND.COM.').
- ^ self.
- ].
-
- "/ pipe readSide is p at:1;
- "/ writeSide is p at:2
-
- slaveFD := (stdOutToStxPipe at:2) fileDescriptor.
- execFdArray := Array
- with:(stxToStdinPipe at:1) fileDescriptor "stdin"
- with:slaveFD "stdout"
- with:slaveFD. "stderr"
-
- outStream := stdOutToStxPipe at:1.
- inStream := stxToStdinPipe at:2.
-
shellAndArgs := OperatingSystem commandAndArgsForOSCommand:aCommand.
shell := shellAndArgs at:1.
args := (shellAndArgs at:2) ? ''.
] ifFalse:[
- "Use a pseudo-tty"
- pty := NonPositionableExternalStream makePTYPair.
- pty isNil ifTrue:[
- self warn:'Cannot open pty.'.
- ^ self.
- ].
-
- "/ pty at:1 is the master;
- "/ pty at:2 is the slave
- inStream := outStream := (pty at:1).
- setupBlock value.
- "/ fork a shell process on the slave-side
- slaveFD := (pty at:2) fileDescriptor.
- execFdArray := Array with:slaveFD with:slaveFD with:slaveFD.
-
aCommand isNil ifTrue:[
shell := OperatingSystem getEnvironment:'SHELL'.
shell size == 0 ifTrue:[
@@ -224,7 +234,7 @@
exec:shell
withArguments:args
environment:env
- fileDescriptors:execFdArray
+ fileDescriptors:execFDArray
fork:true
newPgrp:true
inDirectory:aDirectory.
@@ -476,11 +486,11 @@
!TerminalSession class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/TerminalSession.st,v 1.2 2013-07-07 07:39:35 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/TerminalSession.st,v 1.3 2013-07-07 11:31:18 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/TerminalSession.st,v 1.2 2013-07-07 07:39:35 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/TerminalSession.st,v 1.3 2013-07-07 11:31:18 cg Exp $'
! !