@@ -15,14 +15,18 @@ public protocol TerminalType {
1515 currentDirectoryPath: String ,
1616 environment: [ String : String ]
1717 ) async throws -> String
18-
18+
1919 func terminate( ) async
20+ func writeInput( _ input: String ) async
21+ var isRunning : Bool { get }
2022}
2123
2224public final class Terminal : TerminalType , @unchecked Sendable {
2325 var process : Process ?
2426 var outputPipe : Pipe ?
2527 var inputPipe : Pipe ?
28+
29+ public var isRunning : Bool { process? . isRunning ?? false }
2630
2731 public struct TerminationError : Error {
2832 public let reason : Process . TerminationReason
@@ -84,13 +88,14 @@ public final class Terminal: TerminalType, @unchecked Sendable {
8488 if !( self . process? . isRunning ?? false ) {
8589 let reason = self . process? . terminationReason ?? . exit
8690 let status = self . process? . terminationStatus ?? 1
87- if let output = ( self . process? . standardOutput as? Pipe ) ? . fileHandleForReading. readDataToEndOfFile ( ) ,
88- let content = String ( data: output, encoding: . utf8) ,
89- !content. isEmpty
91+ if let output = ( self . process? . standardOutput as? Pipe ) ? . fileHandleForReading
92+ . readDataToEndOfFile ( ) ,
93+ let content = String ( data: output, encoding: . utf8) ,
94+ !content. isEmpty
9095 {
9196 continuation? . yield ( content)
9297 }
93-
98+
9499 if status == 0 {
95100 continuation? . finish ( )
96101 } else {
@@ -139,15 +144,15 @@ public final class Terminal: TerminalType, @unchecked Sendable {
139144 return result
140145 }
141146
142- func writeInput( _ input: String ) {
147+ public func writeInput( _ input: String ) {
143148 guard let data = input. data ( using: . utf8) else {
144149 return
145150 }
146151
147152 inputPipe? . fileHandleForWriting. write ( data)
148153 inputPipe? . fileHandleForWriting. closeFile ( )
149154 }
150-
155+
151156 public func terminate( ) async {
152157 process? . terminate ( )
153158 process = nil
0 commit comments