Instance Method
customActivity(title:titleAfterIndicator:frames:success:failure:color:)
Creates an activity indicator with custom frames that are iterated over.
func customActivity(title: String, titleAfterIndicator: Bool = true, frames: [String], success: String = "[Done]", failure: String = "[Failed]", color: ConsoleColor = .cyan) -> ActivityIndicator<CustomActivity>
Parameters
titleThe title of the activity indicator.
titleAfterIndicatorIf
true, the title of the activity indicator will be printed after the indicator itself.framesThe strings to loop over as the activity indicator runs.
successThe string to replace the indicator with when the operation succeeds. The default value is
[Done].failureThe string to replace the indicator with when the operation fails: The default value is
[Failed].colorThe color of text when the frames are displayed. The default value is
ConsoleColor.cyan.
Return Value
An ActivityIndicator that can start and stop the indicator.
Discussion
// Create an activity indicator with the strings (frames) to loop over as it runs.
let indicator = console.activity(title: "Loading", frames: ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"])
try await indicator.withActivityIndicator {
// complete the indicator after 3 seconds
try await Task.sleep(for: .seconds(3))
}
Note
If you want some ideas for indicator styles, take a look here: https://github.com/kiliankoe/CLISpinner/blob/master/Sources/CLISpinner/Pattern.swift#L88-L151