@@ -62,7 +62,7 @@ public final class TerminalController {
62
62
}
63
63
64
64
/// Pointer to output stream to operate on.
65
- private var stream : WritableByteStream
65
+ private var stream : _LocalFileOutputByteStream
66
66
67
67
/// Width of the terminal.
68
68
public var width : Int {
@@ -84,13 +84,9 @@ public final class TerminalController {
84
84
private let boldString = " \u{001B} [1m "
85
85
86
86
/// Constructs the instance if the stream is a tty.
87
- public init ? ( stream: WritableByteStream ) {
88
- let realStream = ( stream as? ThreadSafeOutputByteStream ) ? . stream ?? stream
89
-
87
+ public init ? ( stream: _LocalFileOutputByteStream ) {
90
88
// Make sure it is a file stream and it is tty.
91
- guard let fileStream = realStream as? LocalFileOutputByteStream ,
92
- TerminalController . isTTY ( fileStream)
93
- else {
89
+ guard TerminalController . isTTY ( stream) else {
94
90
return nil
95
91
}
96
92
@@ -109,14 +105,14 @@ public final class TerminalController {
109
105
}
110
106
111
107
/// Checks if passed file stream is tty.
112
- public static func isTTY( _ stream: LocalFileOutputByteStream ) -> Bool {
108
+ public static func isTTY( _ stream: _LocalFileOutputByteStream ) -> Bool {
113
109
return terminalType ( stream) == . tty
114
110
}
115
111
116
112
/// Computes the terminal type of the stream.
117
- public static func terminalType( _ stream: LocalFileOutputByteStream ) -> TerminalType {
113
+ public static func terminalType( _ stream: _LocalFileOutputByteStream ) -> TerminalType {
118
114
#if !os(Windows)
119
- if ProcessEnv . block [ " TERM " ] == " dumb " {
115
+ if ProcessInfo . processInfo . environment [ " TERM " ] == " dumb " {
120
116
return . dumb
121
117
}
122
118
#endif
@@ -138,7 +134,7 @@ public final class TerminalController {
138
134
return Int ( csbi. srWindow. Right - csbi. srWindow. Left) + 1
139
135
#else
140
136
// Try to get from environment.
141
- if let columns = ProcessEnv . block [ " COLUMNS " ] , let width = Int ( columns) {
137
+ if let columns = ProcessInfo . processInfo . environment [ " COLUMNS " ] , let width = Int ( columns) {
142
138
return width
143
139
}
144
140
@@ -181,7 +177,7 @@ public final class TerminalController {
181
177
182
178
/// Writes a string to the stream.
183
179
public func write( _ string: String , inColor color: Color = . noColor, bold: Bool = false ) {
184
- writeWrapped ( string, inColor: color, bold: bold, stream : stream )
180
+ stream . send ( writeWrapped ( string, inColor: color, bold: bold) )
185
181
flush ( )
186
182
}
187
183
@@ -193,19 +189,16 @@ public final class TerminalController {
193
189
194
190
/// Wraps the string into the color mentioned.
195
191
public func wrap( _ string: String , inColor color: Color , bold: Bool = false ) -> String {
196
- let stream = BufferedOutputByteStream ( )
197
- writeWrapped ( string, inColor: color, bold: bold, stream: stream)
198
- return stream. bytes. description
192
+ return writeWrapped ( string, inColor: color, bold: bold)
199
193
}
200
194
201
195
private func writeWrapped(
202
- _ string: String , inColor color: Color , bold: Bool = false , stream : WritableByteStream
203
- ) {
196
+ _ string: String , inColor color: Color , bold: Bool = false
197
+ ) -> String {
204
198
// Don't wrap if string is empty or color is no color.
205
199
guard !string. isEmpty && color != . noColor else {
206
- stream. send ( string)
207
- return
200
+ return string
208
201
}
209
- stream . send ( color. string) . send ( bold ? boldString : " " ) . send ( string) . send ( resetString)
202
+ return color. string + ( bold ? boldString : " " ) + string + resetString
210
203
}
211
204
}
0 commit comments