TerminalView.st
changeset 2778 796ab4177728
parent 2678 f475a905c54c
child 2810 d57cc02787de
--- a/TerminalView.st	Wed Nov 24 10:41:25 2004 +0100
+++ b/TerminalView.st	Wed Nov 24 12:10:29 2004 +0100
@@ -232,8 +232,8 @@
 !
 
 openOnInput:inStream output:outStream in:aView
-    "open a terminalView on the given streams (which are typically some
-     kind of socket or pty). 
+    "open a terminalView on the given streams 
+     (which are typically some kind of socket or pty). 
      Keys pressed are sent to inStream, text appearing
      from outStream is displayed in the terminal view.
      This can be used to implement things like rlogin
@@ -248,7 +248,7 @@
 
     vt inStream:inStream.
     vt outStream:outStream.
-    vt startReaderProcess.
+    vt startReaderProcessWhenVisible.
 
     ^ scr
 
@@ -1106,6 +1106,60 @@
     "Modified: / 10.6.1998 / 17:46:59 / cg"
 !
 
+readerProcessLoop
+    "look for the commands output,
+     and send me #processInput:n: events whenever something arrives."
+
+    StreamError handle:[:ex |
+        Transcript show:'Terminal(PTY-reader) [error]: '; showCR:ex description.
+    ] do:[
+        [true] whileTrue:[
+            Object abortSignal handle:[:ex |
+                self showCursor.
+            ] do:[
+                |n sensor|
+
+                outStream readWait.
+                sensor := self sensor.
+                (sensor notNil and:[sensor hasKeyPressEventFor:self]) ifTrue:[
+                    true "(sensor userEventCount > 10)" ifTrue:[
+                        "/ give terminalView a chance to
+                        "/ send out the character.
+                        Delay waitForSeconds:0.01.
+                    ]
+                ] ifFalse:[
+                    n := self readAnyAvailableData.
+                    n > 0 ifTrue:[
+                        shellPid notNil ifTrue:[
+                            self waitForOutputToDrain.
+                        ]
+                    ] ifFalse:[
+                        n == 0 ifTrue:[
+                            "/ Windows IPC has a bug - it always
+                            "/ returns 0 (when the command is idle)
+                            "/ and says its at the end (sigh)
+
+                            OperatingSystem isMSWINDOWSlike ifTrue:[
+                                Delay waitForSeconds:0.01
+                            ] ifFalse:[
+                                outStream atEnd ifTrue:[
+                                    outStream close. outStream := nil.
+                                    inStream close.  inStream := nil.
+                                    Processor activeProcess terminate.
+                                ] ifFalse:[
+                                    "/ this should not happen.
+
+                                    Delay waitForSeconds:0.05
+                                ]
+                            ].
+                        ]
+                    ]
+                ]
+            ]
+        ]
+    ]
+!
+
 reinitialize
     "reinit after a snapIn.
      this is invoked (by the system thread) after a snapShot image restart"
@@ -1152,59 +1206,49 @@
     "Start a reader process, which looks for the commands output,
      and sends me #processInput:n: events whenever something arrives."
 
+    self obsoleteMethodWarning.    
+    self startReaderProcessWhenVisible.
+
+    "
+     VT100TerminalView openShell
+    "
+
+    "Modified: / 5.5.1999 / 17:58:02 / cg"
+    "Modified: / 28.1.2002 / 21:10:13 / micha"
+!
+
+startReaderProcessNow
+    "Start a reader process, which looks for the commands output,
+     and sends me #processInput:n: events whenever something arrives."
+
+    readerProcess isNil ifTrue:[
+        readerProcess := [
+            [
+                self readerProcessLoop.
+            ] ifCurtailed:[
+                readerProcess := nil    
+            ]
+        ] fork. "/ forkAt:9.
+        readerProcess name:'pty reader'.
+    ]
+
+    "
+     VT100TerminalView openShell
+    "
+
+    "Modified: / 5.5.1999 / 17:58:02 / cg"
+    "Modified: / 28.1.2002 / 21:10:13 / micha"
+!
+
+startReaderProcessWhenVisible
+    "Start a reader process, which looks for the commands output,
+     and sends me #processInput:n: events whenever something arrives."
+
     readerProcess isNil ifTrue:[
         readerProcess := [
             [
                 self waitUntilVisible.
-
-                StreamError handle:[:ex |
-                    Transcript show:'Terminal(PTY-reader) [error]: '; showCR:ex description.
-                ] do:[
-                    [true] whileTrue:[
-                        Object abortSignal handle:[:ex |
-                            self showCursor.
-                        ] do:[
-                            |n sensor|
-
-                            outStream readWait.
-                            sensor := self sensor.
-                            (sensor notNil and:[sensor hasKeyPressEventFor:self]) ifTrue:[
-                                true "(sensor userEventCount > 10)" ifTrue:[
-                                    "/ give terminalView a chance to
-                                    "/ send out the character.
-                                    Delay waitForSeconds:0.01.
-                                ]
-                            ] ifFalse:[
-                                n := self readAnyAvailableData.
-                                n > 0 ifTrue:[
-                                    shellPid notNil ifTrue:[
-                                        self waitForOutputToDrain.
-                                    ]
-                                ] ifFalse:[
-                                    n == 0 ifTrue:[
-                                        "/ Windows IPC has a bug - it always
-                                        "/ returns 0 (when the command is idle)
-                                        "/ and says its at the end (sigh)
-
-                                        OperatingSystem isMSWINDOWSlike ifTrue:[
-                                            Delay waitForSeconds:0.01
-                                        ] ifFalse:[
-                                            outStream atEnd ifTrue:[
-                                                outStream close. outStream := nil.
-                                                inStream close.  inStream := nil.
-                                                Processor activeProcess terminate.
-                                            ] ifFalse:[
-                                                "/ this should not happen.
-
-                                                Delay waitForSeconds:0.05
-                                            ]
-                                        ].
-                                    ]
-                                ]
-                            ]
-                        ]
-                    ]
-                ]
+                self readerProcessLoop.
             ] ifCurtailed:[
                 readerProcess := nil    
             ]
@@ -1241,18 +1285,7 @@
 
 !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
+basicStartCommand: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.
@@ -1271,12 +1304,12 @@
         "use two pipes to COMMAND.COM"
         stxToCommandPipe := NonPositionableExternalStream makePipe.
         stxToCommandPipe isNil ifTrue:[
-            ^ self warn:'Could not create pipe to COMMAND.COM.'.
+            self warn:'Could not create pipe to COMMAND.COM.'. ^ self.
         ].
 
         commandToStxPipe := NonPositionableExternalStream makePipe.
         commandToStxPipe isNil ifTrue:[
-            ^ self warn:'Could not create pipe from COMMAND.COM.'.
+            self warn:'Could not create pipe from COMMAND.COM.'. ^ self.
         ].
 
         "/ pipe readSide is p at:1;
@@ -1382,7 +1415,30 @@
         ^ self.
     ].
 
-    self startReaderProcess.
+    "Created: / 20.7.1998 / 18:19:32 / cg"
+    "Modified: / 5.5.1999 / 17:28:37 / cg"
+!
+
+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"
+
+    self basicStartCommand:aCommand in:aDirectory.
+    self startReaderProcessWhenVisible.
 
     "Created: / 20.7.1998 / 18:19:32 / cg"
     "Modified: / 5.5.1999 / 17:28:37 / cg"
@@ -1407,7 +1463,7 @@
      Also fork a reader process, to read the shells output and
      tell me, whenever something arrives"
 
-    ^ self startCommand:nil in:aDirectory
+    self startCommand:nil in:aDirectory
 
     "
      VT100TerminalView openShellIn:'/etc'
@@ -1857,7 +1913,7 @@
 !TerminalView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/TerminalView.st,v 1.123 2004-03-19 18:58:02 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/TerminalView.st,v 1.124 2004-11-24 11:10:29 cg Exp $'
 ! !
 
 TerminalView initialize!