from: github.com/remko/age-plugin-se
This commit is contained in:
19
Sources/Stream.swift
Normal file
19
Sources/Stream.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
import Foundation
|
||||
|
||||
/// Abstraction of a line-based communication stream
|
||||
protocol Stream {
|
||||
func readLine() -> String?
|
||||
func writeLine(_: String)
|
||||
}
|
||||
|
||||
class StandardIOStream: Stream {
|
||||
func readLine() -> String? {
|
||||
return Swift.readLine(strippingNewline: true)
|
||||
}
|
||||
|
||||
func writeLine(_ line: String) {
|
||||
FileHandle.standardOutput.write(line.data(using: .utf8)!)
|
||||
FileHandle.standardOutput.write(Data([0xa]))
|
||||
fflush(stdout)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user