@@ -72,6 +72,9 @@ public final class ProgressBar: Sendable {
7272 $0. subDescription = " "
7373 $0. tasks += 1
7474 }
75+ if config. plain {
76+ render ( force: true )
77+ }
7578 }
7679
7780 /// Updates the additional description of the progress bar.
@@ -80,6 +83,9 @@ public final class ProgressBar: Sendable {
8083 resetCurrentTask ( )
8184
8285 state. withLock { $0. subDescription = subDescription }
86+ if config. plain {
87+ render ( force: true )
88+ }
8389 }
8490
8591 private func start( intervalSeconds: TimeInterval ) async {
@@ -96,6 +102,9 @@ public final class ProgressBar: Sendable {
96102 /// Starts an animation of the progress bar.
97103 /// - Parameter intervalSeconds: The time interval between updates in seconds.
98104 public func start( intervalSeconds: TimeInterval = 0.04 ) {
105+ if config. plain {
106+ return
107+ }
99108 Task ( priority: . utility) {
100109 await start ( intervalSeconds: intervalSeconds)
101110 }
@@ -148,15 +157,15 @@ extension ProgressBar {
148157 if config. showSpinner && !config. showProgressBar {
149158 if !state. finished {
150159 let spinnerIcon = config. theme. getSpinnerIcon ( state. iteration)
151- components. append ( " \( spinnerIcon) " )
160+ components. append ( colorize ( " \( spinnerIcon) " , Color . cyan ) )
152161 } else {
153- components. append ( " \( config. theme. done) " )
162+ components. append ( colorize ( " \( config. theme. done) " , Color . green ) )
154163 }
155164 }
156165
157166 if config. showTasks, let totalTasks = state. totalTasks {
158167 let tasks = min ( state. tasks, totalTasks)
159- components. append ( " [ \( tasks) / \( totalTasks) ] " )
168+ components. append ( colorize ( " [ \( tasks) / \( totalTasks) ] " , Color . cyan ) )
160169 }
161170
162171 if config. showDescription && !state. description. isEmpty {
@@ -172,7 +181,7 @@ extension ProgressBar {
172181 let total = state. totalSize ?? Int64 ( state. totalItems ?? 0 )
173182
174183 if config. showPercent && total > 0 && allowProgress {
175- components. append ( " \( state. finished ? " 100% " : state. percent) " )
184+ components. append ( colorize ( " \( state. finished ? " 100% " : state. percent) " , Color . green ) )
176185 }
177186
178187 if config. showProgressBar, total > 0 , allowProgress {
@@ -181,7 +190,7 @@ extension ProgressBar {
181190 let barLength = state. finished ? remainingWidth : Int ( Int64 ( remainingWidth) * value / total)
182191 let barPaddingLength = remainingWidth - barLength
183192 let bar = " \( String ( repeating: config. theme. bar, count: barLength) ) \( String ( repeating: " " , count: barPaddingLength) ) "
184- components. append ( " | \( bar) | " )
193+ components. append ( " | \( colorize ( bar, Color . green ) ) | " )
185194 }
186195
187196 var additionalComponents = [ String] ( )
@@ -246,13 +255,13 @@ extension ProgressBar {
246255
247256 if additionalComponents. count > 0 {
248257 let joinedAdditionalComponents = additionalComponents. joined ( separator: " , " )
249- components. append ( " ( \( joinedAdditionalComponents) ) " )
258+ components. append ( " ( \( colorize ( joinedAdditionalComponents, Color . cyan ) ) ) " )
250259 }
251260
252261 if config. showTime {
253262 let timeDifferenceSeconds = secondsSinceStart ( )
254263 let formattedTime = timeDifferenceSeconds. formattedTime ( )
255- components. append ( " [ \( formattedTime) ] " )
264+ components. append ( " [ \( colorize ( formattedTime, Color . blue ) ) ] " )
256265 }
257266
258267 return components. joined ( separator: " " )
@@ -286,4 +295,16 @@ extension ProgressBar {
286295 }
287296 return " \( sizeNumber) / \( totalSizeNumber) \( totalSizeUnit) "
288297 }
298+
299+ private func colorize( _ text: String , _ color: String ) -> String {
300+ guard config. color else { return text }
301+ return " \( color) \( text) \( Color . reset) "
302+ }
303+
304+ private enum Color {
305+ static let green = " \u{001B} [32m "
306+ static let cyan = " \u{001B} [36m "
307+ static let blue = " \u{001B} [34m "
308+ static let reset = " \u{001B} [0m "
309+ }
289310}
0 commit comments