@@ -132,30 +132,28 @@ public protocol ProgressBarProtocol {
132
132
}
133
133
134
134
// Simple ProgressBar which shows the update text in new lines.
135
- public final class SimpleProgressBar < Target : OutputStream > : ProgressBarProtocol {
135
+ public final class SimpleProgressBar : ProgressBarProtocol {
136
136
private let header : String
137
137
private var isClear : Bool
138
- private var stream : UnsafeMutablePointer < Target >
138
+ private var stream : OutputByteStream
139
139
140
- init ( stream: UnsafeMutablePointer < Target > , header: String ) {
140
+ init ( stream: OutputByteStream , header: String ) {
141
141
self . stream = stream
142
142
self . header = header
143
143
self . isClear = true
144
144
}
145
145
146
- private func write( _ string: String ) {
147
- stream. pointee. write ( string)
148
- }
149
-
150
146
public func update( percent: Int , text: String ) {
151
147
if isClear {
152
- write ( header)
153
- write ( " \n " )
148
+ stream <<< header
149
+ stream <<< " \n "
150
+ try ? stream. flush ( )
154
151
isClear = false
155
152
}
156
153
157
- write ( " \( percent) %: " + text)
158
- write ( " \n " )
154
+ stream <<< " \( percent) %: " + text
155
+ stream <<< " \n "
156
+ try ? stream. flush ( )
159
157
}
160
158
161
159
public func complete( ) {
@@ -207,8 +205,8 @@ public final class ProgressBar: ProgressBarProtocol {
207
205
}
208
206
209
207
/// Creates colored or simple progress bar based on output stream provided stream.
210
- public func createProgressBar< Target : OutputStream > ( forStream stream: UnsafeMutablePointer < Target > , header: String ) -> ProgressBarProtocol {
211
- if let stdStream = stream. pointee as? LocalFileOutputByteStream , let term = TerminalController ( stream: stdStream) {
208
+ public func createProgressBar( forStream stream: OutputByteStream , header: String ) -> ProgressBarProtocol {
209
+ if let stdStream = stream as? LocalFileOutputByteStream , let term = TerminalController ( stream: stdStream) {
212
210
return ProgressBar ( term: term, header: header)
213
211
}
214
212
return SimpleProgressBar ( stream: stream, header: header)
0 commit comments