TerminalSession.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Jun 2019 14:28:51 +0200
changeset 5050 44fa8672d102
parent 4676 e9e8de763fb7
child 5072 1a686ebe8711
permissions -rw-r--r--
#DOCUMENTATION by cg class: SharedQueue comment/format in: #next #nextWithTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
     1
"{ Encoding: utf8 }"
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
     2
4271
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
     3
"
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
     4
 COPYRIGHT (c) 2013 by eXept Software AG
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
     5
              All Rights Reserved
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
     6
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
     7
 This software is furnished under a license and may be used
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
     8
 only in accordance with the terms of that license and with the
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
     9
 inclusion of the above copyright notice. This software may not
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    10
 be provided or otherwise made available to, or used by, any
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    11
 other person. No title to or ownership of the software is
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    12
 hereby transferred.
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    13
"
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
3595
d212572ec418 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3317
diff changeset
    16
"{ NameSpace: Smalltalk }"
d212572ec418 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3317
diff changeset
    17
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Object subclass:#TerminalSession
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:'inStream outStream errStream readerProcess shellPid shellCommand
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
		shellDirectory readerDelay pluggableCheckBeforeReadAction
3038
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
    21
		pluggableProcessInputAction execFDArray stxToStdinPipe
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
    22
		stdOutToStxPipe pty ptyName terminatedAction collectedOutput
3095
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
    23
		promptActions'
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
	classVariableNames:'Debug'
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
	poolDictionaries:''
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
	category:'Views-TerminalViews'
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
!TerminalSession class methodsFor:'documentation'!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
4271
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    31
copyright
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    32
"
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    33
 COPYRIGHT (c) 2013 by eXept Software AG
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    34
              All Rights Reserved
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    35
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    36
 This software is furnished under a license and may be used
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    37
 only in accordance with the terms of that license and with the
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    38
 inclusion of the above copyright notice. This software may not
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    39
 be provided or otherwise made available to, or used by, any
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    40
 other person. No title to or ownership of the software is
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    41
 hereby transferred.
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    42
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    43
"
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    44
!
5a950926374f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4186
diff changeset
    45
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
documentation
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
"
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    48
    This is basically a TerminalView without a view.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    49
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    This keeps the state and API to interact with another program
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    via a terminal session. Under Unix, a pseudo-tty connection
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    is used; other operating systems might use other mechanisms.
4027
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
    53
3315
2b2c0d24f156 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3302
diff changeset
    54
    This is (currently) used by the GDBApplication, to interact
3981
aa54de68b481 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3725
diff changeset
    55
    with gdb, cscope and the program.
aa54de68b481 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3725
diff changeset
    56
    It can be used wherever more control is needed than a simple pipe
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    offers (such as terminal emulation, window size, CTRL-c support etc.)
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
4027
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
    59
    A major feature is a mechanism to catch certain prompt strings of the output
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
    60
    and get a notification.
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
    61
    This is very useful, if a program's output is to be shown both in a terminalview,
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
    62
    and also to be analyzed for robot actions.
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
    63
    Applications for this are telnet like interaction, interactions with a debugger
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
    64
    or monitor (gdb, android-adb) etc.,
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
    65
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
    66
    A lot of code has been extracted from TerminalView, 
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
    67
    which will be refactored, once this is stable. 
3981
aa54de68b481 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3725
diff changeset
    68
    For now, there is some code duplication (as of Summer 2014).
3315
2b2c0d24f156 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3302
diff changeset
    69
2b2c0d24f156 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3302
diff changeset
    70
    outStream   - the controlled program's output (a pty-half)
2b2c0d24f156 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3302
diff changeset
    71
    inStream    - the controlled program's input (a pty-half)
2b2c0d24f156 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3302
diff changeset
    72
    errStream   - the controlled program's output (a pty-half)
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
"
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    74
!
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    75
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    76
examples
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    77
"
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    78
    |session|
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    79
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    80
    session := TerminalSession new.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    81
    session startReaderProcess.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    82
    session 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    83
        pluggableProcessInputAction:[:buffer :n |
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    84
            Transcript show:(buffer copyTo:n).
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    85
            Transcript endEntry.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    86
        ].
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    87
    session 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    88
        startCommand:'ls -l' in:'~' 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    89
        environment:nil 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    90
        setupTerminalWith:[] 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    91
        terminatedAction:[ Transcript showCR:'finished' ].
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    92
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    93
    session 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    94
        startCommand:'(cd ~/work/cg/schemeNew ; make)' in:'~' 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    95
        environment:nil 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    96
        setupTerminalWith:[] 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    97
        terminatedAction:[ Transcript showCR:'finished' ].
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    98
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
    99
    session 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   100
        startCommand:'(ls ~/work/cg/schemeNew)' in:'~' 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   101
        environment:nil 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   102
        setupTerminalWith:[] 
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   103
        terminatedAction:[ Transcript showCR:'finished' ].
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   104
"
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
! !
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
!TerminalSession class methodsFor:'initialization'!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
initialize
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    Debug := false.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    "
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
     self initialize
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   115
     Debug := true.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    "
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
! !
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
!TerminalSession methodsFor:'accessing'!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
errStream
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   122
    "the stdErrToStx stream.
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   123
     Stuff written by the process' to its stderr will appear here"
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   124
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    ^ errStream
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
inStream
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   129
    "the stxTostdIn stream.
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   130
     Stuff written to this stream will appear at the process' stdin"
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   131
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    ^ inStream
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
outStream
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   136
    "the process' stdOutToStx stream.
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   137
     Stuff written by the process to its stdout will appear here"
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   138
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    ^ outStream
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   142
pluggableCheckBeforeReadAction:aBlockOrNil
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   143
    pluggableCheckBeforeReadAction := aBlockOrNil.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   146
pluggableProcessInputAction:aBlockOrNil
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   147
    pluggableProcessInputAction := aBlockOrNil.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
3039
2f36acd9c8b2 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
   150
pty
2f36acd9c8b2 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
   151
    ^ pty
2f36acd9c8b2 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
   152
!
2f36acd9c8b2 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
   153
3040
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   154
ptyName
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   155
    ^ ptyName
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   156
!
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   157
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
shellCommand
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
    ^ shellCommand
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
shellDirectory
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
    ^ shellDirectory
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
shellPid
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    ^ shellPid
3084
43ba6ede1157 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3069
diff changeset
   168
!
43ba6ede1157 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3069
diff changeset
   169
4301
0972b064ccee #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4271
diff changeset
   170
terminatedAction:aBlock
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   171
    "hook to be called when terminated"
4301
0972b064ccee #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4271
diff changeset
   172
    
0972b064ccee #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4271
diff changeset
   173
    terminatedAction := aBlock.
0972b064ccee #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4271
diff changeset
   174
0972b064ccee #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4271
diff changeset
   175
    "Modified (comment): / 07-02-2017 / 16:05:55 / cg"
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
! !
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
!TerminalSession methodsFor:'initialization & release'!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
closeDownShell
4553
2ca69f94e1c5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4552
diff changeset
   181
    "shut down my shell process"
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   183
    self closeDownShell:1
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   184
!
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   185
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   186
closeDownShell:waitTimeInSeconds
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   187
    "shut down my shell process"
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   188
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   189
    |pid waitTime|
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    (pid := shellPid) notNil ifTrue:[
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   192
        Logger info:'killing shell pid=%1' with:shellPid.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
        Debug ifTrue:[
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   194
            Logger info:'killing shell pid=%1' with:pid.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
        ].
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   196
        OperatingSystem terminateProcessGroup:pid.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
        OperatingSystem terminateProcess:pid.
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   198
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   199
        waitTime := 0.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   200
        [shellPid notNil and:[waitTime < waitTimeInSeconds]] whileTrue:[
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   201
            Delay waitForSeconds:0.1.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   202
            waitTime := waitTime + 0.1
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   203
        ].
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   204
        Logger info:'shell pid after SIGTERM=%1' with:shellPid.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   205
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   206
        "/ still not dead?
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
        shellPid notNil ifTrue:[
4643
b01920109e34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4642
diff changeset
   208
            Logger info:'still not dead after %1' with:waitTimeInSeconds.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
            OperatingSystem isMSWINDOWSlike ifFalse:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
                OperatingSystem killProcessGroup:pid.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
            ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
            OperatingSystem killProcess:pid.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
            shellPid := nil.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
        ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
        OperatingSystem closePid:pid.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
    "Modified: / 5.5.1999 / 18:43:02 / cg"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
4553
2ca69f94e1c5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4552
diff changeset
   221
closeDownShellAndStopReaderProcess
4625
0c4ea1bf37ba #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4555
diff changeset
   222
    "shut down my shell process, stop the background reader thread
0c4ea1bf37ba #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4555
diff changeset
   223
     and close the streams"
4553
2ca69f94e1c5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4552
diff changeset
   224
2ca69f94e1c5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4552
diff changeset
   225
    self closeDownShell.
2ca69f94e1c5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4552
diff changeset
   226
    self stopReaderProcess.
2ca69f94e1c5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4552
diff changeset
   227
    self closeStreams
2ca69f94e1c5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4552
diff changeset
   228
!
2ca69f94e1c5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4552
diff changeset
   229
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
closeStreams
4554
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   231
    |s|
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   232
3037
47f022308e7d class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3028
diff changeset
   233
    self stopReaderProcess.
47f022308e7d class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3028
diff changeset
   234
4554
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   235
    (s := inStream) notNil ifTrue:[
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   236
        inStream := nil.
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   237
        s isStream ifTrue:[s close].
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    ].
4554
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   239
    (s := outStream) notNil ifTrue:[
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   240
        outStream := nil.
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   241
        s close.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    ].
4554
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   243
    (s := errStream) notNil ifTrue:[
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   244
        errStream := nil.
41d1d0047772 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4553
diff changeset
   245
        s close.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
3038
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   249
createTerminalConnectionAndSetupWith:setupBlock
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   250
    "create a terminal connection (pseudo terminal or pipe)"
3038
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   251
3040
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   252
    |slaveFD master slave ptyTriple|
3038
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   253
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   254
    OperatingSystem isMSWINDOWSlike ifTrue:[
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   255
        "use two pipes (eg. to COMMAND.COM)"
3038
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   256
        stxToStdinPipe := NonPositionableExternalStream makePipe.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   257
        stxToStdinPipe isNil ifTrue:[
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   258
            self error:(self class classResources string:'Could not create pipe to COMMAND.COM.') mayProceed:true. 
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   259
            ^ self.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   260
        ].
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   261
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   262
        stdOutToStxPipe := NonPositionableExternalStream makePipe.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   263
        stdOutToStxPipe isNil ifTrue:[
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   264
            self error:(self class classResources classResources string:'Could not create pipe from COMMAND.COM.') mayProceed:true. 
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   265
            ^ self.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   266
        ].
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   267
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   268
        "/ pipe readSide is p at:1;
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   269
        "/      writeSide is p at:2
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   270
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   271
        slaveFD := (stdOutToStxPipe at:2) fileDescriptor.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   272
        execFDArray := Array 
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   273
                         with:(stxToStdinPipe at:1) fileDescriptor        "stdin"
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   274
                         with:slaveFD                                       "stdout"
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   275
                         with:slaveFD.                                      "stderr"
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   276
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   277
        outStream := stdOutToStxPipe at:1.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   278
        inStream  := stxToStdinPipe at:2.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   279
    ] ifFalse:[
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   280
        "Use a pseudo-tty"
3040
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   281
        ptyTriple := OperatingSystem makePTY.
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   282
        ptyTriple isNil ifTrue:[
3038
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   283
            self warn:'Cannot open pty.'.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   284
            ^ self.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   285
        ].
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   286
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   287
        "/ pty at:1 is the master;
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   288
        "/ pty at:2 is the slave
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   289
        "/ pty at:3 is the name of the pty
3040
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   290
        ptyName := ptyTriple at:3.
3039
2f36acd9c8b2 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
   291
3040
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   292
        master := NonPositionableExternalStream forReadWriteToFileDescriptor:(ptyTriple at:1).
3039
2f36acd9c8b2 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
   293
        master buffered:false.
2f36acd9c8b2 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
   294
3040
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   295
        slave := NonPositionableExternalStream forReadWriteToFileDescriptor:(ptyTriple at:2).
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   296
        slave buffered:false.
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   297
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   298
        pty := { master . slave }.
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   299
3039
2f36acd9c8b2 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
   300
        inStream := outStream := master.
3038
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   301
        setupBlock value.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   302
        "/ fork a shell process on the slave-side
3040
c455569df459 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3039
diff changeset
   303
        slaveFD := (ptyTriple at:2).
3038
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   304
        execFDArray := Array with:slaveFD with:slaveFD with:slaveFD.
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   305
    ].
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   306
!
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   307
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
reinitialize
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
    shellPid := nil.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
    inStream := outStream := errStream := nil.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
3084
43ba6ede1157 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3069
diff changeset
   313
startCommand:aCommand in:aDirectory environment:envIn setupTerminalWith:setupBlock terminatedAction:terminatedActionArg
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   314
    "start a command on a pseudo terminal. 
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   315
     If the command arg is nil, a shell is started. 
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   316
     If aDirectory is nil, the command is executed in the current directory.
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   317
     Also fork a reader process, to read the shell's output 
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   318
     and tell me, whenever something arrives"
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   320
    |exitStatus 
3088
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   321
     cmd shell args env shellAndArgs didOpenTerminal|
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
    shellCommand := aCommand.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
    shellDirectory := aDirectory.
3084
43ba6ede1157 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3069
diff changeset
   325
    terminatedAction := terminatedActionArg.
3088
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   326
    didOpenTerminal := false.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   328
    env := Dictionary new.
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   329
    env declareAllFrom:envIn.
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   330
3085
bd99146f19bf class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3084
diff changeset
   331
    (inStream isNil or:[outStream isNil]) ifTrue:[
bd99146f19bf class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3084
diff changeset
   332
        self createTerminalConnectionAndSetupWith:setupBlock.
3088
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   333
        didOpenTerminal := true.
3085
bd99146f19bf class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3084
diff changeset
   334
    ].
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
    OperatingSystem isMSWINDOWSlike ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
        shellAndArgs := OperatingSystem commandAndArgsForOSCommand:aCommand.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
        shell := shellAndArgs at:1.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
        args  := (shellAndArgs at:2) ? ''.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
    ] ifFalse:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
        aCommand isNil ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
            shell := OperatingSystem getEnvironment:'SHELL'.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
            shell size == 0 ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
                shell := '/bin/sh'.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
            ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
            cmd := shell asFilename baseName.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
            args := (Array with:cmd).
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
        ] ifFalse:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
            shell := '/bin/sh'.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
            args := (Array with:'sh' with:'-c' with:aCommand).
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
        ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
        env at:'SHELL' put:shell.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
    shellPid := Processor
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
               monitor:[
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   356
                  Debug ifTrue:[
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   357
                      Logger info:'exec: "%1" args: "%2"' with:shell with:args.
4550
f2d6c8249ad8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
   358
                  ].
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
                  OperatingSystem
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
                      exec:shell
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
                      withArguments:args
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
                      environment:env
3038
c418ee215311 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3037
diff changeset
   363
                      fileDescriptors:execFDArray
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
                      fork:true
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
                      newPgrp:true
4060
c81f01b9d936 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4028
diff changeset
   366
                      inDirectory:aDirectory
c81f01b9d936 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4028
diff changeset
   367
                      showWindow:false.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
               ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
               action:[:status |
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
                    Debug ifTrue:[
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   371
                        Logger info:'pid: %1' with:status pid.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   372
                        Logger info:'status %1:' with:status status.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   373
                        Logger info:'code: %1' with:status code.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   374
                        Logger info:'core %1:' with:status core.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
                    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
                    status stillAlive ifFalse:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
                        exitStatus := status.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
                        OperatingSystem closePid:shellPid.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
                        shellPid := nil.
3135
623a3d09191b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   380
                        terminatedAction valueWithOptionalArgument:status
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
                    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
               ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   384
    Logger info:'started shell pid: %1' with:shellPid.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   385
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
    "close the slave side of the pty/pipes (only used by the child)"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
    pty notNil ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
        (pty at:2) close.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
3088
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   391
    didOpenTerminal ifTrue:[
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   392
        stdOutToStxPipe notNil ifTrue:[
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   393
            (stdOutToStxPipe at:2) close.
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   394
            (stxToStdinPipe at:1) close.
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   395
        ].
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
3088
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   397
        shellPid isNil ifTrue:[
3069
4c01425c7095 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
   398
        "/ self warn:'Cannot start shell'.
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   399
            outStream notNil ifTrue:[outStream close].
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   400
            inStream notNil ifTrue:[inStream close].
3088
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   401
            inStream := outStream := nil.
52f83256a664 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   402
        ].
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
    ].
3069
4c01425c7095 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
   404
    ^ shellPid
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
3069
4c01425c7095 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
   406
    "Created: / 20-07-1998 / 18:19:32 / cg"
4c01425c7095 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
   407
    "Modified: / 01-08-2013 / 20:38:37 / cg"
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
! !
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
!TerminalSession methodsFor:'input / output'!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
paste:someText
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
    "paste - redefined to send the chars to the shell instead
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
     of pasting into the view"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
    |s nLines|
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
    s := someText.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
    s isString ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
        s := s asStringCollection
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
    ] ifFalse:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
        (s isKindOf:StringCollection) ifFalse:[
4643
b01920109e34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4642
diff changeset
   423
            self warn:'selection (' , s class name , ') is not convertable to text'.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
            ^ self
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
        ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
    (nLines := s size) == 0 ifTrue:[^ self].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
    (nLines == 1 and:[(s at:1) size == 0]) ifTrue:[^ self].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
    s keysAndValuesDo:[:idx :line |
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
        line notNil ifTrue:[inStream nextPutAll:line].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
        idx ~~ nLines ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
            self sendLineEnd.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
        ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
    "Modified: / 12.6.1998 / 22:12:47 / cg"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
4676
e9e8de763fb7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4643
diff changeset
   439
send:aString
e9e8de763fb7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4643
diff changeset
   440
    inStream nextPutAll:aString.
e9e8de763fb7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4643
diff changeset
   441
e9e8de763fb7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4643
diff changeset
   442
    "Created: / 26-05-2018 / 11:32:04 / Claus Gittinger"
e9e8de763fb7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4643
diff changeset
   443
!
e9e8de763fb7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4643
diff changeset
   444
3112
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   445
sendCharacter:aCharacter
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   446
    inStream nextPut:aCharacter.
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   447
!
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   448
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
sendLine:aString
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
    inStream nextPutAll:aString.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
    self sendLineEnd
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
sendLineEnd
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
    OperatingSystem isMSDOSlike ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
        inStream nextPut:Character return.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
        inStream nextPut:Character linefeed.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
    ] ifFalse:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
        inStream nextPut:Character return.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
! !
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
!TerminalSession methodsFor:'misc'!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   465
collectedOutput
3097
529fbe182ce0 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3096
diff changeset
   466
    "return any collected output, so far"
529fbe182ce0 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3096
diff changeset
   467
529fbe182ce0 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3096
diff changeset
   468
    collectedOutput isNil ifTrue:[^ nil].
529fbe182ce0 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3096
diff changeset
   469
    ^ collectedOutput contents
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   470
!
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   471
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
defineWindowSizeLines:numberOfLines columns:numberOfColumns
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
    "/ any idea, how to do this under windows ?
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
    OperatingSystem isUNIXlike ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
        "/
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
        "/ tell the pty;
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
        "/ tell the shell;
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
        "/
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
        (inStream notNil 
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
        and:[inStream isExternalStream
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
        and:[inStream isOpen]]) ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
            Debug ifTrue:[
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   483
                Logger info:'TerminalSession [info]: changed len to %1' with:numberOfLines.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
            ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
            (OperatingSystem 
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
                setWindowSizeOnFileDescriptor:inStream fileDescriptor
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
                width:numberOfColumns
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
                height:numberOfLines) ifFalse:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
                Debug ifTrue:[
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   490
                    Logger info:'TerminalSession [warning]: cannot change windowSize'.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   491
                ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
            ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
        ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
        shellPid notNil ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
            OperatingSystem sendSignal:OperatingSystem sigWINCH to:shellPid
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
        ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
    "Created: / 11.6.1998 / 22:51:39 / cg"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
    "Modified: / 5.5.1999 / 19:45:09 / cg"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
3110
2e9ebced59e6 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3097
diff changeset
   504
forgetPrompt:aString
4027
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   505
    "/ Transcript show:'forget prompt: '; showCR:aString.
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   506
    promptActions removeKey:aString ifAbsent:[].
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   507
    "/ Transcript show:'prompts now: '; showCR:promptActions.
3110
2e9ebced59e6 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3097
diff changeset
   508
!
2e9ebced59e6 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3097
diff changeset
   509
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   510
onPrompt:aString do:aBlock
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   511
    "remember what to do, when a prompt arrives;
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   512
     notice: will only start checking for prompt, when startCollectingOutput
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   513
     has been called."
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   514
4027
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   515
    "/ Transcript show:'add prompt: '; showCR:aString.
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   516
    promptActions isNil ifTrue:[promptActions := Dictionary new].
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   517
    promptActions at:aString put:aBlock
3095
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   518
!
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   519
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   520
onPrompt:string1 do:block1 onPrompt:string2 do:block2
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   521
    "remember what to do, when a prompt arrives;
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   522
     notice: will only start checking for prompt, when startCollectingOutput
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   523
     has been called."
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   524
4027
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   525
    "/ Transcript show:'add prompt: '; showCR:string1.
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   526
    "/ Transcript show:'add prompt: '; showCR:string2.
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   527
    promptActions isNil ifTrue:[promptActions := Dictionary new].
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   528
    promptActions 
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   529
        at:string1 put:block1;
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   530
        at:string2 put:block2.
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   531
!
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   532
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   533
outputFromAction:aBlock prompt:prompt timeout:seconds
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   534
    "evaluate aBlock and wait for the prompt.
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   535
     return gdb output as string collection"
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   536
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   537
    ^ self
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   538
        outputFromAction:aBlock 
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   539
        prompt:prompt 
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   540
        timeout:seconds
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   541
        to:nil
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   542
!
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   543
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   544
outputFromAction:aBlock prompt:prompt timeout:seconds to:aStreamOrNil
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   545
    "evaluate aBlock and wait for the prompt.
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   546
     return gdb output as string collection"
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   547
3112
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   548
    |sema output lastSize gotPrompt|
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   549
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   550
    sema := Semaphore new.
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   551
    aStreamOrNil isNil ifTrue:[
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   552
        self startCollectingOutput.
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   553
    ] ifFalse:[
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   554
        self startCollectingOutputTo:aStreamOrNil
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   555
    ].
4551
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   556
    self onPrompt:prompt do:[:strings | output := strings. sema signalOnce. ].
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   557
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   558
    aBlock value.
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   559
3112
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   560
    lastSize := 0.
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   561
    [
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   562
        |newSize|
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   563
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   564
        (gotPrompt := (sema waitWithTimeout:seconds) notNil) ifFalse:[
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   565
            newSize := collectedOutput size.
4551
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   566
            self debuggingCodeFor:#cg is:[
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   567
                Logger info:'timeout - output size is: %1' with:newSize.
4551
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   568
                (newSize between:1 and:1000) ifTrue:[
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   569
                    Logger info:'output is: "%1"' with:collectedOutput contents.
4551
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   570
                ].
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   571
            ].
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   572
3595
d212572ec418 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3317
diff changeset
   573
            newSize > 100000 ifTrue:[
d212572ec418 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3317
diff changeset
   574
                self stopCollectingOutput.
d212572ec418 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3317
diff changeset
   575
                self onPrompt:nil do:nil.
d212572ec418 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3317
diff changeset
   576
                collectedOutput := nil.
d212572ec418 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3317
diff changeset
   577
                TimeoutError raiseRequestErrorString:'GDB output too big'.
d212572ec418 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3317
diff changeset
   578
            ].
3112
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   579
            newSize = lastSize ifTrue:[
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   580
                "/ self information:'Error: command timeout.'.
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   581
                self stopCollectingOutput.
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   582
                self onPrompt:nil do:nil.
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   583
                TimeoutError raiseRequestErrorString:'GDB command timeout'.
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   584
            ].
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   585
            lastSize := newSize.
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   586
        ].  
4551
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   587
    ] doUntil:[ gotPrompt ].
3112
48fe32a582b4 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3111
diff changeset
   588
3111
9db40cb12c21 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3110
diff changeset
   589
    output notEmptyOrNil ifTrue:[
9db40cb12c21 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3110
diff changeset
   590
        output first isEmpty ifTrue:[
9db40cb12c21 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3110
diff changeset
   591
            "/ self halt.
9db40cb12c21 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3110
diff changeset
   592
            output := output copyFrom:2
9db40cb12c21 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3110
diff changeset
   593
        ].
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   594
    ].
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   595
    ^ output
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   596
!
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   597
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   598
outputFromCommand:aCommand prompt:prompt timeout:seconds
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   599
    "return a command's output as string collection"
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   600
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   601
    ^ self
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   602
        outputFromCommand:aCommand 
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   603
        prompt:prompt 
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   604
        timeout:seconds 
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   605
        to:nil
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   606
!
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   607
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   608
outputFromCommand:aCommand prompt:prompt timeout:seconds to:aStreamOrNil
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   609
    "return a command's output as string collection"
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   610
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   611
    |output firstLine|
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   612
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   613
    output := self 
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   614
                outputFromAction:[ self sendLine:aCommand ]
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   615
                prompt:prompt 
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   616
                timeout:seconds
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   617
                to:aStreamOrNil.
3111
9db40cb12c21 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3110
diff changeset
   618
    output isEmptyOrNil ifTrue:[^ output].
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   619
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   620
    "/ the first line of output is the echo
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   621
    firstLine := output first withoutLeadingSeparators.
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   622
    firstLine ~= aCommand ifTrue:[
3135
623a3d09191b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   623
        (aCommand startsWith:firstLine) ifTrue:[
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   624
            "/ sigh - it is sometimes truncated (to be investigated)
4028
5cade94eea34 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4027
diff changeset
   625
            self breakPoint:#cg.
3135
623a3d09191b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   626
            ^ output.
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   627
        ].
3135
623a3d09191b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   628
        "/ self halt.
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   629
        ^ output.
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   630
    ].
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   631
    ^ output copyFrom:2
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   632
!
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   633
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   634
sendInterruptSignal
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
    "send an INT-signal to the shell (UNIX only)"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   636
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   637
    shellPid notNil ifTrue:[
4551
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   638
        OperatingSystem isUNIXlike ifTrue:[
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   639
            OperatingSystem interruptProcessGroup:shellPid.
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   640
            OperatingSystem interruptProcess:shellPid.
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   641
        ] ifFalse:[
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   642
            'TerminalSession [info]: IRQ unimplemented for DOS' infoPrintCR.
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   643
        ].
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   644
    ] ifFalse:[
96b63e5277cb #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4550
diff changeset
   645
        'TerminalSession [info]: no shell' infoPrintCR.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
    "Modified: / 10.6.1998 / 17:49:49 / cg"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
sendKillSignal
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
    "send a KILL-signal to the shell (UNIX only)"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   654
    shellPid notNil ifTrue:[
3722
2038d4cd1afa #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
   655
        OperatingSystem killProcessGroup:shellPid.
2038d4cd1afa #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
   656
        OperatingSystem killProcess:shellPid.
2038d4cd1afa #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
   657
        OperatingSystem childProcessWait:false pid:shellPid.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
    ]
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   659
!
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   660
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   661
startCollectingOutput
3097
529fbe182ce0 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3096
diff changeset
   662
    "start collecting output in a collecting stream"
529fbe182ce0 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3096
diff changeset
   663
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   664
    self startCollectingOutputTo:(WriteStream on:(String new:1000)).
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   665
!
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   666
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   667
startCollectingOutputTo:aStream
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   668
    "start collecting output into a collecting (or other) stream"
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   669
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   670
    collectedOutput := aStream.
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   671
!
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   672
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   673
stopCollectingOutput
3097
529fbe182ce0 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3096
diff changeset
   674
    "start collecting output in a collecting stream"
529fbe182ce0 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3096
diff changeset
   675
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   676
    collectedOutput := nil.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   677
! !
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   678
4552
58fa57876769 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4551
diff changeset
   679
!TerminalSession methodsFor:'queries'!
58fa57876769 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4551
diff changeset
   680
58fa57876769 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4551
diff changeset
   681
isOpen
58fa57876769 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4551
diff changeset
   682
    (inStream notNil and:[inStream isOpen]) ifTrue:[^ true].
58fa57876769 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4551
diff changeset
   683
    (outStream notNil and:[outStream isOpen]) ifTrue:[^ true]. 
58fa57876769 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4551
diff changeset
   684
    (errStream notNil and:[errStream isOpen]) ifTrue:[^ true]. 
58fa57876769 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4551
diff changeset
   685
    ^ false
58fa57876769 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4551
diff changeset
   686
! !
58fa57876769 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4551
diff changeset
   687
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   688
!TerminalSession methodsFor:'reader process'!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   690
collectOutputAndCheckForPrompt:buffer count:n
3110
2e9ebced59e6 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3097
diff changeset
   691
    |string collectedString collectedLines i i2 lastLine|
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   692
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   693
    collectedOutput isNil ifTrue:[^ self].
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   694
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   695
    string := buffer copyTo:n.
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   696
    collectedOutput nextPutAll:string.
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   697
4027
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   698
    "/ Transcript showCR:'prompts: '; showCR:promptActions.
3095
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   699
    promptActions notNil ifTrue:[
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   700
        collectedString := collectedOutput contents.
4643
b01920109e34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4642
diff changeset
   701
        i := collectedString lastIndexOf:(Character lf).
3713
a02088a8910d #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3595
diff changeset
   702
        i ~~ 0 ifTrue:[
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   703
            lastLine := (collectedString copyFrom:i+1) withoutTrailingSeparators.
3110
2e9ebced59e6 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3097
diff changeset
   704
            lastLine isEmpty ifTrue:[
4643
b01920109e34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4642
diff changeset
   705
                i2 := collectedString lastIndexOf:(Character lf) startingAt:(i-1).
3713
a02088a8910d #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 3595
diff changeset
   706
                i2 ~~ 0 ifTrue:[
3110
2e9ebced59e6 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3097
diff changeset
   707
                    lastLine := (collectedString copyFrom:i2+1 to:i-1) withoutTrailingSeparators.
2e9ebced59e6 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3097
diff changeset
   708
                ].
2e9ebced59e6 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3097
diff changeset
   709
            ].
4027
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   710
            "/ Transcript show:' got: <'; show:lastLine; showCR:'>'. "/ ; showCR:lastLine asByteArray.
3095
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   711
            promptActions keysAndValuesDo:[:expectedPrompt :promptAction |
4027
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   712
                "/ Transcript show:'  looking for: '; showCR:expectedPrompt.
3095
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   713
                ((lastLine endsWith:expectedPrompt) 
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   714
                or:[ (lastLine startsWith:expectedPrompt) ]) ifTrue:[
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   715
                    "/ ('found prompt; call ',promptAction printString) printCR.
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   716
3095
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   717
                    "/ perform the promptaction
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   718
                    collectedLines := collectedString asStringCollection 
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   719
                                        collect:[:each | 
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   720
                                            (each endsWith:String crlf) 
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   721
                                                    ifTrue:[ each copyButLast:2 ]
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   722
                                                    ifFalse:[
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   723
                                                        (each endsWith:Character return) 
3317
4602d20cdba0 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3315
diff changeset
   724
                                                            ifTrue:[ each copyButLast ]
3095
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   725
                                                            ifFalse:[ each ]]].
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   726
                    collectedLines removeLast.  "/ the prompt itself
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   727
                    promptAction value: collectedLines.
4027
c08940786e9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3981
diff changeset
   728
                ].
3095
10715ba9921b class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3088
diff changeset
   729
            ].
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   730
        ].
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   731
    ].
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   732
!
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   733
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   734
readAnyAvailableData
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   735
    "read data from the stream,
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
     and sends me #processInput:n: events if something arrived.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
     Returns the amount of data read."
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   739
    |buffer bufferSize n|
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
    outStream isNil ifTrue:[^ 0].   "/ already closed
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
3132
cadb44acf325 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   743
    bufferSize := 1024.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
    buffer := String new:bufferSize.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   745
4186
553f2b640cc8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4060
diff changeset
   746
    StreamError handle:[:ex |
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   747
        n := 0
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   748
    ] do:[
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   749
        |line|
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   750
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   751
        collectedOutput class == ActorStream ifTrue:[
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   752
            (outStream readWaitWithTimeout:0.5) ifTrue:[
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   753
                n := 0
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   754
            ] ifFalse:[
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   755
                line := outStream nextLine,Character cr.
4643
b01920109e34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4642
diff changeset
   756
                "/ Transcript showCR:('line: "',line,'"').
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   757
                n := line size.
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   758
                pluggableProcessInputAction notNil ifTrue:[
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   759
                    pluggableProcessInputAction value:line value:n.
3285
dded4dc30bac class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   760
                ].
dded4dc30bac class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   761
                collectedOutput notNil ifTrue:[
dded4dc30bac class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   762
                    self collectOutputAndCheckForPrompt:line count:n.
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   763
                ]
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   764
            ]
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   765
        ] ifFalse:[
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   766
            n := outStream nextAvailableBytes:bufferSize into:buffer startingAt:1.
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   767
            n > 0 ifTrue:[
4643
b01920109e34 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4642
diff changeset
   768
                "/ Transcript showCR:('buffer: "',(buffer copyTo:n),'"').
3285
dded4dc30bac class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   769
                pluggableProcessInputAction notNil ifTrue:[
dded4dc30bac class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   770
                    pluggableProcessInputAction value:buffer value:n.
dded4dc30bac class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3276
diff changeset
   771
                ].
3276
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   772
                collectedOutput notNil ifTrue:[
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   773
                    self collectOutputAndCheckForPrompt:buffer count:n
180b977dcbe5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   774
                ].
3087
21384929202f class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3085
diff changeset
   775
            ].
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   776
        ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   778
    ^ n
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   779
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   780
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   781
readerProcessLoop
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   782
    "look for the session's output"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   783
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   784
    StreamError handle:[:ex |
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
        Transcript show:'Terminal(PTY-reader) [error]: '; showCR:ex description.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
    ] do:[
4641
561fd5fdf03c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4639
diff changeset
   787
        |outStreamWasNonNil|
561fd5fdf03c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4639
diff changeset
   788
561fd5fdf03c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4639
diff changeset
   789
        outStreamWasNonNil := false.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   790
        [true] whileTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   791
            AbortOperationRequest handle:[:ex |
3096
e3e3a28294f5 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3095
diff changeset
   792
                ^ self
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
            ] do:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
                |n sensor|
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
                readerDelay notNil ifTrue:[ Delay waitForSeconds:readerDelay].
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   797
                outStream isNil ifTrue:[
4641
561fd5fdf03c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4639
diff changeset
   798
                    outStreamWasNonNil ifTrue:[^ self].
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   799
                    Delay waitForSeconds:0.1
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   800
                ] ifFalse:[
4641
561fd5fdf03c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4639
diff changeset
   801
                    outStreamWasNonNil := true.
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   802
                    outStream readWait.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   803
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   804
                    (pluggableCheckBeforeReadAction isNil
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   805
                    or:[pluggableCheckBeforeReadAction value]) ifTrue:[
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   806
                        n := self readAnyAvailableData.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   807
                        n == 0 ifTrue:[
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   808
                            "/ Windows IPC has a bug - it always
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   809
                            "/ returns 0 (when the command is idle)
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   810
                            "/ and says it's at the end (sigh)
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   811
                            OperatingSystem isMSWINDOWSlike ifTrue:[
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   812
                                Delay waitForSeconds:0.1
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
                            ] ifFalse:[
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   814
                                outStream atEnd ifTrue:[
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   815
                                    outStream close. outStream := nil.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   816
                                    inStream close.  inStream := nil.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   817
                                    Processor activeProcess terminate.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   818
                                ] ifFalse:[
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   819
                                    "/ this should not happen.
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   820
                                    Delay waitForSeconds:0.1
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   821
                                ]
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   822
                            ].
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   823
                        ]
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
                    ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
                ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   826
            ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   827
        ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   828
    ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   829
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
startReaderProcess
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
    "Start a reader process, which looks for the commands output,
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   833
     and sends me #processInput:n: events whenever something arrives."
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   834
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   835
    Logger info:'start reader'.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
    readerProcess isNil ifTrue:[
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
        readerProcess := [
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
            [
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
                self readerProcessLoop.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
            ] ifCurtailed:[
4642
695b02c145a9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4641
diff changeset
   841
                "/ read any remaining data
695b02c145a9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4641
diff changeset
   842
                (self readAnyAvailableData > 0) ifTrue:[
695b02c145a9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4641
diff changeset
   843
                    self halt:'to check if this solves the make problem'.
695b02c145a9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4641
diff changeset
   844
                ].
695b02c145a9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4641
diff changeset
   845
                readerProcess := nil.   
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   846
            ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
        ] fork. "/ forkAt:9.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
        readerProcess name:'pty reader'.
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
    ]
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   850
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
    "
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
     VT100TerminalView openShell
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   853
    "
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   854
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   855
    "Modified: / 5.5.1999 / 17:58:02 / cg"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   856
    "Modified: / 28.1.2002 / 21:10:13 / micha"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   858
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   859
stopReaderProcess
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
    "stop the background reader thread"
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
3037
47f022308e7d class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3028
diff changeset
   862
    |p|
47f022308e7d class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3028
diff changeset
   863
4639
3e5713fe4685 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4625
diff changeset
   864
    Logger info:'stop reader'.
3037
47f022308e7d class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3028
diff changeset
   865
    (p := readerProcess) notNil ifTrue:[
47f022308e7d class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3028
diff changeset
   866
        readerProcess := nil.
47f022308e7d class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3028
diff changeset
   867
        p terminate.
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
        "/ give it a chance to really terminate
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   869
        Processor yield.
4642
695b02c145a9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4641
diff changeset
   870
        [p isDead] whileFalse:[
695b02c145a9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4641
diff changeset
   871
            Delay waitForSeconds:0.05
4641
561fd5fdf03c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4639
diff changeset
   872
        ].
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   873
    ].
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   874
! !
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   875
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
!TerminalSession class methodsFor:'documentation'!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   878
version
3595
d212572ec418 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3317
diff changeset
   879
    ^ '$Header$'
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   880
!
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   881
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   882
version_CVS
3595
d212572ec418 class: TerminalSession
Claus Gittinger <cg@exept.de>
parents: 3317
diff changeset
   883
    ^ '$Header$'
3028
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   884
! !
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   885
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   886
e49cf8755fd6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   887
TerminalSession initialize!