--- a/TerminalView.st Wed May 07 16:56:39 2003 +0200
+++ b/TerminalView.st Wed May 07 17:00:33 2003 +0200
@@ -928,187 +928,7 @@
"Modified: / 20.6.1998 / 20:30:34 / cg"
! !
-!TerminalView methodsFor:'initialization-shell'!
-
-startCommand:aCommand
- "start a command on a pseudo terminal. If the command arg is nil,
- a shell is started. The command is started in the current directory.
- Also fork a reader process, to read the shells output and
- tell me, whenever something arrives"
-
- ^ self startCommand:aCommand in:nil
-
- "Modified: / 20.7.1998 / 18:30:24 / cg"
-!
-
-startCommand:aCommand in:aDirectory
- "start a command on a pseudo terminal. If the command arg is nil,
- a shell is started. If aDirectory is not nil, the command is
- executed in that directory.
- Also fork a reader process, to read the shells output and
- tell me, whenever something arrives"
-
- |pty slaveFD execFdArray blocked exitStatus
- stxToCommandPipe commandToStxPipe cmd shell args env shellAndArgs|
-
- shellCommand := aCommand.
- shellDirectory := aDirectory.
-
- self create. "/ need my windowID (to pass down in environment)
-
- OperatingSystem isMSWINDOWSlike ifTrue:[
- "use two pipes to COMMAND.COM"
- stxToCommandPipe := ExternalStream makePipe.
- stxToCommandPipe isNil ifTrue:[
- ^ self warn:'Could not create pipe to COMMAND.COM.'.
- ].
-
- commandToStxPipe := ExternalStream makePipe.
- commandToStxPipe isNil ifTrue:[
- ^ self warn:'Could not create pipe from COMMAND.COM.'.
- ].
-
- "/ pipe readSide is p at:1;
- "/ writeSide is p at:2
-
- slaveFD := (commandToStxPipe at:2) fileDescriptor.
- execFdArray := Array
- with:(stxToCommandPipe at:1) fileDescriptor "stdin"
- with:slaveFD "stdout"
- with:slaveFD. "stderr"
-
- outStream := commandToStxPipe at:1.
- inStream := stxToCommandPipe at:2.
- outStream buffered:false.
- inStream buffered:false.
-
- shellAndArgs := OperatingSystem commandAndArgsForOSCommand:aCommand.
- shell := shellAndArgs at:1.
- args := (shellAndArgs at:2) ? ''.
- ] ifFalse:[
- "Use a pseudo-tty"
- pty := ExternalStream 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).
- inStream buffered:false.
-
- self defineWindowSize.
- "/ 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:[
- shell := '/bin/sh'.
- ].
- cmd := shell asFilename baseName.
- args := (Array with:cmd).
- ] ifFalse:[
- shell := '/bin/sh'.
- args := (Array with:'sh' with:'-c' with:aCommand).
- ].
- env := Dictionary new.
- env at:'SHELL' put:shell.
- env at:'TERM' put:(self terminalType).
- env at:'LINES' put:(numberOfLines printString).
- env at:'COLUMNS' put:(numberOfColumns printString).
- (device platformName = 'X11' and:[drawableId notNil]) ifTrue:[
- env at:'WINDOWID' put:(drawableId address printString).
- ].
- ].
-
- blocked := OperatingSystem blockInterrupts.
-
- shellPid := Processor
- monitor:[
- OperatingSystem
- exec:shell
- withArguments:args
- environment:env
- fileDescriptors:execFdArray
- fork:true
- newPgrp:true
- inDirectory:aDirectory.
- ]
- action:[:status |
- Debug ifTrue:[
- Transcript show:'pid:'; showCR:status pid.
- Transcript show:'status:'; showCR:status status.
- Transcript show:'code:'; showCR:status code.
- Transcript show:'core:'; showCR:status core.
- ].
- status stillAlive ifFalse:[
- exitStatus := status.
- OperatingSystem closePid:shellPid.
- shellPid := nil.
- self pushEvent:#shellTerminated
- ].
- ].
-
- blocked ifFalse:[
- OperatingSystem unblockInterrupts
- ].
-
- "close the slave side of the pty/pipes (only used by the child)"
- pty notNil ifTrue:[
- (pty at:2) close.
- ].
-
- commandToStxPipe notNil ifTrue:[
- (commandToStxPipe at:2) close.
- (stxToCommandPipe at:1) close.
- ].
-
- shellPid isNil ifTrue:[
- self warn:'Cannot start shell'.
- outStream close.
- inStream close.
- inStream := outStream := nil.
- ^ self.
- ].
-
- self startReaderProcess.
-
- "Created: / 20.7.1998 / 18:19:32 / cg"
- "Modified: / 5.5.1999 / 17:28:37 / cg"
-!
-
-startShell
- "start a shell on a pseudo terminal in the current directory.
- Also fork a reader process, to read the shells output and
- tell me, whenever something arrives"
-
- ^ self startCommand:nil
-
- "
- VT100TerminalView openShell
- "
-
- "Modified: / 20.7.1998 / 18:29:54 / cg"
-!
-
-startShellIn:aDirectory
- "start a shell on a pseudo terminal in some directory.
- Also fork a reader process, to read the shells output and
- tell me, whenever something arrives"
-
- ^ self startCommand:nil in:aDirectory
-
- "
- VT100TerminalView openShellIn:'/etc'
- "
-
- "Modified: / 20.7.1998 / 18:29:46 / cg"
-! !
-
-!TerminalView methodsFor:'initialize / release'!
+!TerminalView methodsFor:'initialization & release'!
closeDownShell
"shut down my shell process and stop the background reader thread."
@@ -1417,6 +1237,186 @@
"Modified: / 21.7.1998 / 19:00:13 / cg"
! !
+!TerminalView methodsFor:'initialization-shell'!
+
+startCommand:aCommand
+ "start a command on a pseudo terminal. If the command arg is nil,
+ a shell is started. The command is started in the current directory.
+ Also fork a reader process, to read the shells output and
+ tell me, whenever something arrives"
+
+ ^ self startCommand:aCommand in:nil
+
+ "Modified: / 20.7.1998 / 18:30:24 / cg"
+!
+
+startCommand:aCommand in:aDirectory
+ "start a command on a pseudo terminal. If the command arg is nil,
+ a shell is started. If aDirectory is not nil, the command is
+ executed in that directory.
+ Also fork a reader process, to read the shells output and
+ tell me, whenever something arrives"
+
+ |pty slaveFD execFdArray blocked exitStatus
+ stxToCommandPipe commandToStxPipe cmd shell args env shellAndArgs|
+
+ shellCommand := aCommand.
+ shellDirectory := aDirectory.
+
+ self create. "/ need my windowID (to pass down in environment)
+
+ OperatingSystem isMSWINDOWSlike ifTrue:[
+ "use two pipes to COMMAND.COM"
+ stxToCommandPipe := ExternalStream makePipe.
+ stxToCommandPipe isNil ifTrue:[
+ ^ self warn:'Could not create pipe to COMMAND.COM.'.
+ ].
+
+ commandToStxPipe := ExternalStream makePipe.
+ commandToStxPipe isNil ifTrue:[
+ ^ self warn:'Could not create pipe from COMMAND.COM.'.
+ ].
+
+ "/ pipe readSide is p at:1;
+ "/ writeSide is p at:2
+
+ slaveFD := (commandToStxPipe at:2) fileDescriptor.
+ execFdArray := Array
+ with:(stxToCommandPipe at:1) fileDescriptor "stdin"
+ with:slaveFD "stdout"
+ with:slaveFD. "stderr"
+
+ outStream := commandToStxPipe at:1.
+ inStream := stxToCommandPipe at:2.
+ outStream buffered:false.
+ inStream buffered:false.
+
+ shellAndArgs := OperatingSystem commandAndArgsForOSCommand:aCommand.
+ shell := shellAndArgs at:1.
+ args := (shellAndArgs at:2) ? ''.
+ ] ifFalse:[
+ "Use a pseudo-tty"
+ pty := ExternalStream 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).
+ inStream buffered:false.
+
+ self defineWindowSize.
+ "/ 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:[
+ shell := '/bin/sh'.
+ ].
+ cmd := shell asFilename baseName.
+ args := (Array with:cmd).
+ ] ifFalse:[
+ shell := '/bin/sh'.
+ args := (Array with:'sh' with:'-c' with:aCommand).
+ ].
+ env := Dictionary new.
+ env at:'SHELL' put:shell.
+ env at:'TERM' put:(self terminalType).
+ env at:'LINES' put:(numberOfLines printString).
+ env at:'COLUMNS' put:(numberOfColumns printString).
+ (device platformName = 'X11' and:[drawableId notNil]) ifTrue:[
+ env at:'WINDOWID' put:(drawableId address printString).
+ ].
+ ].
+
+ blocked := OperatingSystem blockInterrupts.
+
+ shellPid := Processor
+ monitor:[
+ OperatingSystem
+ exec:shell
+ withArguments:args
+ environment:env
+ fileDescriptors:execFdArray
+ fork:true
+ newPgrp:true
+ inDirectory:aDirectory.
+ ]
+ action:[:status |
+ Debug ifTrue:[
+ Transcript show:'pid:'; showCR:status pid.
+ Transcript show:'status:'; showCR:status status.
+ Transcript show:'code:'; showCR:status code.
+ Transcript show:'core:'; showCR:status core.
+ ].
+ status stillAlive ifFalse:[
+ exitStatus := status.
+ OperatingSystem closePid:shellPid.
+ shellPid := nil.
+ self pushEvent:#shellTerminated
+ ].
+ ].
+
+ blocked ifFalse:[
+ OperatingSystem unblockInterrupts
+ ].
+
+ "close the slave side of the pty/pipes (only used by the child)"
+ pty notNil ifTrue:[
+ (pty at:2) close.
+ ].
+
+ commandToStxPipe notNil ifTrue:[
+ (commandToStxPipe at:2) close.
+ (stxToCommandPipe at:1) close.
+ ].
+
+ shellPid isNil ifTrue:[
+ self warn:'Cannot start shell'.
+ outStream close.
+ inStream close.
+ inStream := outStream := nil.
+ ^ self.
+ ].
+
+ self startReaderProcess.
+
+ "Created: / 20.7.1998 / 18:19:32 / cg"
+ "Modified: / 5.5.1999 / 17:28:37 / cg"
+!
+
+startShell
+ "start a shell on a pseudo terminal in the current directory.
+ Also fork a reader process, to read the shells output and
+ tell me, whenever something arrives"
+
+ ^ self startCommand:nil
+
+ "
+ VT100TerminalView openShell
+ "
+
+ "Modified: / 20.7.1998 / 18:29:54 / cg"
+!
+
+startShellIn:aDirectory
+ "start a shell on a pseudo terminal in some directory.
+ Also fork a reader process, to read the shells output and
+ tell me, whenever something arrives"
+
+ ^ self startCommand:nil in:aDirectory
+
+ "
+ VT100TerminalView openShellIn:'/etc'
+ "
+
+ "Modified: / 20.7.1998 / 18:29:46 / cg"
+! !
+
!TerminalView methodsFor:'menu'!
doReset
@@ -1819,7 +1819,7 @@
!TerminalView class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/TerminalView.st,v 1.114 2003-05-07 14:45:31 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/TerminalView.st,v 1.115 2003-05-07 15:00:20 cg Exp $'
! !
TerminalView initialize!