@@ -12,7 +12,9 @@ class CEActiveTaskTerminalView: CELocalShellTerminalView {
1212 var activeTask : CEActiveTask
1313
1414 private var cachedCaretColor : NSColor ?
15- private( set) var isUserCommandRunning : Bool = false
15+ var isUserCommandRunning : Bool {
16+ activeTask. status == . running || activeTask. status == . stopped
17+ }
1618 private var enableOutput : Bool = false
1719
1820 init ( activeTask: CEActiveTask ) {
@@ -28,7 +30,6 @@ class CEActiveTaskTerminalView: CELocalShellTerminalView {
2830 super. setup ( )
2931 terminal. parser. oscHandlers [ 133 ] = { [ weak self] slice in
3032 guard let string = String ( bytes: slice, encoding: . utf8) , let self else { return }
31-
3233 // There's some more commands we could handle but don't right now. See the section on the FinalTerm codes
3334 // here: https://iterm2.com/documentation-escape-codes.html
3435 // There's also a few codes we don't emit. This should be improved in the future.
@@ -39,27 +40,24 @@ class CEActiveTaskTerminalView: CELocalShellTerminalView {
3940 self . cachedCaretColor = self . caretColor
4041 }
4142 self . caretColor = self . cachedCaretColor ?? self . caretColor
43+ self . activeTask. updateTaskStatus ( to: . running)
4244
4345 self . sendOutputMessage ( " Starting task: " + self . activeTask. task. name)
4446 self . sendOutputMessage ( self . activeTask. task. command)
4547 self . newline ( )
4648
4749 // Command started
48- self . isUserCommandRunning = true
4950 self . enableOutput = true
5051 case " D " :
52+ // Disabled before we've received the first C CMD from the task
53+ guard enableOutput else { return }
5154 // Command terminated with code
52- if self . isUserCommandRunning == true {
53- self . isUserCommandRunning = false
54- self . enableOutput = false
55- let chunks = string. split ( separator: " ; " )
56- guard chunks. count == 2 , let code = Int32 ( chunks [ 1 ] ) else { return }
57-
58- if self . activeTask. status == . running {
59- self . activeTask. handleProcessFinished ( terminationStatus: code)
60- }
61- self . caretColor = . clear
62- }
55+ let chunks = string. split ( separator: " ; " )
56+ guard chunks. count == 2 , let status = Int32 ( chunks [ 1 ] ) else { return }
57+ self . activeTask. handleProcessFinished ( terminationStatus: status)
58+
59+ self . enableOutput = false
60+ self . caretColor = . clear
6361 default :
6462 break
6563 }
@@ -91,7 +89,7 @@ class CEActiveTaskTerminalView: CELocalShellTerminalView {
9189 )
9290
9391 terminalEnvironment. append ( contentsOf: environment)
94- terminalEnvironment. append ( " CE_SHELL_INTEGRATION_DISABLE_PROMPT =1" )
92+ terminalEnvironment. append ( " \( ShellIntegration . Variables . disableHistory ) =1 " )
9593 terminalEnvironment. append (
9694 contentsOf: activeTask. task. environmentVariables. map ( { $0. key + " = " + $0. value } )
9795 )
@@ -130,7 +128,7 @@ class CEActiveTaskTerminalView: CELocalShellTerminalView {
130128 }
131129
132130 func newline( ) {
133- // cr cr lf (it's what zsh sends on a cmdRet)
131+ // cr cr lf
134132 feed ( byteArray: [ 13 , 13 , 10 ] )
135133 }
136134
@@ -141,38 +139,11 @@ class CEActiveTaskTerminalView: CELocalShellTerminalView {
141139 return nil
142140 }
143141
144- func getChildProcesses( ) -> [ pid_t ] {
145- var children : [ pid_t ] = [ ]
146- guard let parentPID = runningPID ( ) else { return [ ] }
147-
148- // Get number of processes
149- let numProcs = proc_listallpids ( nil , 0 )
150- guard numProcs > 0 else { return children }
151-
152- // Allocate buffer for PIDs
153- let pids = UnsafeMutablePointer< pid_t> . allocate( capacity: Int ( numProcs) )
154- defer { pids. deallocate ( ) }
155-
156- // Get all PIDs
157- let actualNumProcs = proc_listallpids ( pids, numProcs * Int32( MemoryLayout< pid_t> . size) )
158-
159- // Check each process
160- for idx in 0 ..< Int ( actualNumProcs) {
161- var taskInfo = proc_taskallinfo ( )
162- let size = proc_pidinfo (
163- pids [ idx] ,
164- PROC_PIDTASKALLINFO,
165- 0 ,
166- & taskInfo,
167- Int32 ( MemoryLayout< proc_taskallinfo> . size)
168- )
169-
170- if size > 0 && taskInfo. pbsd. pbi_ppid == parentPID {
171- children. append ( pids [ idx] )
172- }
173- }
174-
175- return children
142+ func getProcessGroup( ) -> pid_t ? {
143+ guard let shellPID = runningPID ( ) else { return nil }
144+ let group = getpgid ( shellPID)
145+ guard group >= 0 else { return nil }
146+ return group
176147 }
177148
178149 func getBufferAsString( ) -> String {
@@ -186,7 +157,7 @@ class CEActiveTaskTerminalView: CELocalShellTerminalView {
186157 if enableOutput {
187158 super. dataReceived ( slice: slice)
188159 } else if slice. count >= 5 {
189- // ESC [ 1 3 3 in UTF8
160+ // ESC [ 1 3 3
190161 let sequence : [ UInt8 ] = [ 0x1B , 0x5D , 0x31 , 0x33 , 0x33 ]
191162 // Ignore until we see an OSC 133 code
192163 for idx in 0 ..< ( slice. count - 5 ) where slice [ idx..< idx + 5 ] == sequence [ 0 ..< 5 ] {
0 commit comments