@@ -18,6 +18,17 @@ import Foundation
1818
1919/// A configuration for displaying a progress bar.
2020public struct ProgressConfig : Sendable {
21+ /// The output mode for progress display.
22+ public enum OutputMode : Sendable {
23+ /// No progress output.
24+ case none
25+ /// ANSI control sequences without color (default).
26+ case ansi
27+ /// Plain text output, one line per update.
28+ case plain
29+ /// ANSI control sequences with color.
30+ case color
31+ }
2132 /// The file handle for progress updates.
2233 let terminal : FileHandle
2334 /// The initial description of the progress bar.
@@ -63,12 +74,8 @@ public struct ProgressConfig: Sendable {
6374 public let theme : ProgressTheme
6475 /// The flag indicating whether to clear the progress bar before resetting the cursor.
6576 public let clearOnFinish : Bool
66- /// The flag indicating whether to update the progress bar.
67- public let disableProgressUpdates : Bool
68- /// The flag indicating whether to use colors.
69- public let color : Bool
70- /// The flag indicating whether to use plain output (no ANSI codes, one line per update).
71- public let plain : Bool
77+ /// The output mode for progress display.
78+ public let outputMode : OutputMode
7279 /// Creates a new instance of `ProgressConfig`.
7380 /// - Parameters:
7481 /// - terminal: The file handle for progress updates. The default value is `FileHandle.standardError`.
@@ -91,9 +98,7 @@ public struct ProgressConfig: Sendable {
9198 /// - width: The width of the progress bar in characters. The default value is `120`.
9299 /// - theme: The theme of the progress bar. The default value is `nil`.
93100 /// - clearOnFinish: The flag indicating whether to clear the progress bar before resetting the cursor. The default is `true`.
94- /// - disableProgressUpdates: The flag indicating whether to update the progress bar. The default is `false`.
95- /// - color: A flag indicating whether to enable ANSI color output. The default value is `false`.
96- /// - plain: A flag indicating whether to force plain output with no control sequences. The default value is `false`.
101+ /// - outputMode: The output mode for progress display. The default value is `.ansi`.
97102 public init (
98103 terminal: FileHandle = . standardError,
99104 description: String = " " ,
@@ -115,9 +120,7 @@ public struct ProgressConfig: Sendable {
115120 width: Int = 120 ,
116121 theme: ProgressTheme ? = nil ,
117122 clearOnFinish: Bool = true ,
118- disableProgressUpdates: Bool = false ,
119- color: Bool = false ,
120- plain: Bool = false
123+ outputMode: OutputMode = . ansi
121124 ) throws {
122125 if let totalTasks {
123126 guard totalTasks > 0 else {
@@ -140,11 +143,11 @@ public struct ProgressConfig: Sendable {
140143 self . initialSubDescription = subDescription
141144 self . initialItemsName = itemsName
142145
143- self . showSpinner = plain ? false : showSpinner
146+ self . showSpinner = ( outputMode == . plain || outputMode == . none ) ? false : showSpinner
144147 self . showTasks = showTasks
145148 self . showDescription = showDescription
146149 self . showPercent = showPercent
147- self . showProgressBar = plain ? false : showProgressBar
150+ self . showProgressBar = ( outputMode == . plain || outputMode == . none ) ? false : showProgressBar
148151 self . showItems = showItems
149152 self . showSize = showSize
150153 self . showSpeed = showSpeed
@@ -158,9 +161,7 @@ public struct ProgressConfig: Sendable {
158161 self . width = width
159162 self . theme = theme ?? DefaultProgressTheme ( )
160163 self . clearOnFinish = clearOnFinish
161- self . disableProgressUpdates = disableProgressUpdates
162- self . color = plain ? false : color
163- self . plain = plain
164+ self . outputMode = outputMode
164165 }
165166}
166167
0 commit comments