TerminalView.st
changeset 997 c899373aac1d
parent 992 2f4282cab560
child 999 51cf32d15468
equal deleted inserted replaced
996:f3674765d8fb 997:c899373aac1d
     1 TextCollector subclass:#TerminalView
     1 TextCollector subclass:#TerminalView
     2 	instanceVariableNames:'inStream outStream readerProcess shellPid kbdSequences
     2 	instanceVariableNames:'inStream outStream readerProcess shellPid kbdSequences
     3 		escapeSequenceTree currentSequence currentTree kbdMap
     3 		escapeSequenceTree currentSequence currentTree kbdMap
     4 		escapeLeadingChars numberOfColumns numberOfLines
     4 		escapeLeadingChars numberOfColumns numberOfLines
     5 		shellTerminateAction rangeStartLine rangeEndLine'
     5 		shellTerminateAction rangeStartLine rangeEndLine state'
     6 	classVariableNames:''
     6 	classVariableNames:''
     7 	poolDictionaries:''
     7 	poolDictionaries:''
     8 	category:'Views-TerminalViews'
     8 	category:'Views-TerminalViews'
     9 !
     9 !
    10 
    10 
   133 
   133 
   134 openShell
   134 openShell
   135     "start a shell on a pseudo-TTY, open a terminalView on it
   135     "start a shell on a pseudo-TTY, open a terminalView on it
   136      (i.e. this is kind of an xterm)"
   136      (i.e. this is kind of an xterm)"
   137 
   137 
   138     ^ self startShellIn:nil
   138     ^ self openShellIn:nil
   139 
   139 
   140     "
   140     "
   141      VT100TerminalView openShell
   141      VT100TerminalView openShell
   142     "
   142     "
   143 
   143 
   144     "Modified: / 20.7.1998 / 18:28:26 / cg"
   144     "Modified: / 21.7.1998 / 18:24:55 / cg"
   145 !
   145 !
   146 
   146 
   147 openShellIn:aDirectory
   147 openShellIn:aDirectory
   148     "start a shell on a pseudo-TTY, open a terminalView on it
   148     "start a shell on a pseudo-TTY, open a terminalView on it
   149      (i.e. this is kind of an xterm)"
   149      (i.e. this is kind of an xterm)"
   547         OperatingSystem closePid:pid.
   547         OperatingSystem closePid:pid.
   548     ].
   548     ].
   549 
   549 
   550     readerProcess notNil ifTrue:[
   550     readerProcess notNil ifTrue:[
   551         readerProcess terminate.
   551         readerProcess terminate.
       
   552         "/ give it a chance to really terminate
       
   553         Processor yield.
   552         readerProcess := nil
   554         readerProcess := nil
   553     ].
   555     ].
   554     inStream notNil ifTrue:[
   556     inStream notNil ifTrue:[
   555         inStream close.
   557         inStream close.
   556         inStream := nil
   558         inStream := nil
   558     outStream notNil ifTrue:[
   560     outStream notNil ifTrue:[
   559         outStream close.
   561         outStream close.
   560         outStream := nil
   562         outStream := nil
   561     ].
   563     ].
   562 
   564 
   563     "Modified: / 10.6.1998 / 17:53:49 / cg"
   565     "/ flush any leftover input-processing events
       
   566     self sensor flushEventsFor:self withType:#processInput:n:.
       
   567 
       
   568     "Modified: / 21.7.1998 / 19:00:13 / cg"
   564 !
   569 !
   565 
   570 
   566 destroy
   571 destroy
   567     self closeDownShell.
   572     self closeDownShell.
   568     super destroy
   573     super destroy
   692                         ] do:[
   697                         ] do:[
   693                             |buffer n|
   698                             |buffer n|
   694 
   699 
   695                             outStream readWait.
   700                             outStream readWait.
   696                             (self sensor hasKeyPressEventFor:self) ifTrue:[
   701                             (self sensor hasKeyPressEventFor:self) ifTrue:[
   697                                 Processor yield
   702                                 (self sensor eventCount > 10) ifTrue:[
       
   703                                     "/ give terminalView a chance to
       
   704                                     "/ send out the character.
       
   705                                     Delay waitForSeconds:0.1.
       
   706                                 ]
   698                             ] ifFalse:[
   707                             ] ifFalse:[
   699                                 buffer := String new:1024.
   708                                 buffer := String new:1024.
   700                                 n := outStream nextAvailableBytes:1024 into:buffer startingAt:1.
   709                                 n := outStream nextAvailableBytes:1024 into:buffer startingAt:1.
   701 
   710 
   702                                 n > 0 ifTrue:[
   711                                 n > 0 ifTrue:[
   703                                     self pushEvent:#processInput:n: with:buffer with:n.
   712                                     self pushEvent:#processInput:n: with:buffer with:n.
       
   713                                     (self sensor eventCount > 50) ifTrue:[
       
   714                                         [self sensor eventCount > 10] whileTrue:[
       
   715                                             "/ give terminalView a chance to
       
   716                                             "/ catch up.
       
   717                                             Delay waitForSeconds:0.1.
       
   718                                         ]
       
   719                                     ].
   704                                 ] ifFalse:[
   720                                 ] ifFalse:[
   705                                     n == 0 ifTrue:[
   721                                     n == 0 ifTrue:[
   706                                         outStream atEnd ifTrue:[
   722                                         outStream atEnd ifTrue:[
   707                                             outStream close. outStream := nil.
   723                                             outStream close. outStream := nil.
   708                                             inStream close.  inStream := nil.
   724                                             inStream close.  inStream := nil.
   716                     ]
   732                     ]
   717                 ]
   733                 ]
   718             ] valueOnUnwindDo:[
   734             ] valueOnUnwindDo:[
   719                 readerProcess := nil    
   735                 readerProcess := nil    
   720             ]
   736             ]
   721         ] fork.
   737         ] fork. "/ forkAt:9.
       
   738         readerProcess name:'pty reader'.
   722     ]
   739     ]
   723 
   740 
   724     "
   741     "
   725      VT100TerminalView openShell
   742      VT100TerminalView openShell
   726     "
   743     "
   727 
   744 
   728     "Modified: / 12.6.1998 / 20:59:05 / cg"
   745     "Modified: / 21.7.1998 / 19:32:57 / cg"
   729 ! !
   746 ! !
   730 
   747 
   731 !TerminalView methodsFor:'initialization-shell'!
   748 !TerminalView methodsFor:'initialization-shell'!
   732 
   749 
   733 startCommand:aCommand
   750 startCommand:aCommand
   907 ! !
   924 ! !
   908 
   925 
   909 !TerminalView methodsFor:'processing - input'!
   926 !TerminalView methodsFor:'processing - input'!
   910 
   927 
   911 processInput:buffer n:count
   928 processInput:buffer n:count
       
   929     |sensor|
       
   930 
   912     self hideCursor.
   931     self hideCursor.
   913     1 to:count do:[:i |
   932 
   914         self nextPut:(buffer at:i).
   933 access critical:[
   915     ].
   934     |i i2 s crnlFollows|
   916 
   935 
   917     (self sensor hasEvent:#processInput:n: for:self) ifFalse:[
   936     i := 1.
   918         self endEntry.
   937     [i <= count] whileTrue:[
   919         self showCursor.
   938         (state == 0) ifTrue:[
   920         "/ self makeCursorVisible.
   939             "/ in initial state.
       
   940             "/ quick scan forward for next control character ...
       
   941             i2 := buffer indexOfControlCharacterStartingAt:i.
       
   942             i2 == 0 ifTrue:[
       
   943                 "/ no control characters - simply append all
       
   944                 "/ to the outstanding lines ...
       
   945                 s := buffer copyFrom:i to:count.
       
   946                 i := count + 1. "/ leave loop.
       
   947                 crnlFollows := false.
       
   948             ] ifFalse:[
       
   949                 i2 > i ifTrue:[
       
   950                     s := buffer copyFrom:i to:i2-1.
       
   951                     i := i2. "/ proceed withcontrol character
       
   952                     crnlFollows := false.
       
   953                     i < (count - 1) ifTrue:[
       
   954                         (buffer at:i) == Character return ifTrue:[
       
   955                             (buffer at:i+1) == Character nl ifTrue:[
       
   956                                 crnlFollows := true.
       
   957                                 i := i + 2.
       
   958                             ]
       
   959                         ]
       
   960                     ].
       
   961                 ]
       
   962             ].
       
   963         ].
       
   964 
       
   965         s notNil ifTrue:[
       
   966             currentEmphasis notNil ifTrue:[
       
   967                 s := s emphasizeAllWith:currentEmphasis
       
   968             ].
       
   969 
       
   970             outstandingLine size > 0 ifTrue:[
       
   971                 outstandingLine := outstandingLine , s.
       
   972             ] ifFalse:[
       
   973                 outstandingLine := s.
       
   974             ].
       
   975             crnlFollows ifTrue:[
       
   976                 outstandingLines isNil ifTrue:[
       
   977                     outstandingLines := OrderedCollection with:outstandingLine
       
   978                 ] ifFalse:[
       
   979                     outstandingLines add:outstandingLine.
       
   980                 ].
       
   981                 outstandingLine := ''.
       
   982             ].
       
   983             s := nil.
       
   984 
       
   985             collecting ifTrue:[
       
   986                 flushPending ifFalse:[
       
   987                     self installDelayedUpdate
       
   988                 ] ifTrue:[
       
   989 "/                    outstandingLines size > collectSize ifTrue:[
       
   990 "/                        self endEntry
       
   991 "/                    ]
       
   992                 ]
       
   993             ] ifFalse:[
       
   994                 self endEntry
       
   995             ].
       
   996         ] ifFalse:[
       
   997             "/ no chunk to append (in an escape sequence)
       
   998             "/ must handle individual characters
       
   999             "/ to update the state machine.
       
  1000             self nextPut:(buffer at:i).
       
  1001             i := i + 1.
       
  1002         ]
       
  1003     ].
       
  1004 
       
  1005 ].
       
  1006 
       
  1007     (sensor := self sensor) notNil ifTrue:[
       
  1008         (sensor hasEvent:#processInput:n: for:self) ifFalse:[
       
  1009             self endEntry.
       
  1010             self showCursor.
       
  1011             "/ self makeCursorVisible.
       
  1012         ] ifTrue:[
       
  1013             outstandingLines size > collectSize ifTrue:[ 
       
  1014                 self endEntry.
       
  1015                 self showCursor.
       
  1016                 "/ self makeCursorVisible.
       
  1017                 "/ redraw
       
  1018                 windowGroup notNil ifTrue:[
       
  1019                     windowGroup processRealExposeEventsFor:self.
       
  1020                 ]
       
  1021             ].
       
  1022         ]
   921     ].
  1023     ].
   922 
  1024 
   923     "Created: / 10.6.1998 / 17:26:09 / cg"
  1025     "Created: / 10.6.1998 / 17:26:09 / cg"
   924     "Modified: / 20.6.1998 / 19:18:07 / cg"
  1026     "Modified: / 21.7.1998 / 19:30:18 / cg"
   925 ! !
  1027 ! !
   926 
  1028 
   927 !TerminalView methodsFor:'queries'!
  1029 !TerminalView methodsFor:'queries'!
   928 
  1030 
   929 preferredExtent
  1031 preferredExtent
   971 ! !
  1073 ! !
   972 
  1074 
   973 !TerminalView class methodsFor:'documentation'!
  1075 !TerminalView class methodsFor:'documentation'!
   974 
  1076 
   975 version
  1077 version
   976     ^ '$Header: /cvs/stx/stx/libwidg2/TerminalView.st,v 1.45 1998-07-20 16:30:39 cg Exp $'
  1078     ^ '$Header: /cvs/stx/stx/libwidg2/TerminalView.st,v 1.46 1998-07-21 17:33:37 cg Exp $'
   977 ! !
  1079 ! !