Skip to content

Instance Method

customActivity(frames:success:failure:)

Creates an activity indicator with custom frames that are iterated over.
func customActivity(frames: [ConsoleText], success: String = "[Done]", failure: String = "[Failed]") -> ActivityIndicator<CustomActivity>

Parameters

frames

The text to loop over as the activity indicator runs.

success

The string to replace the indicator with when the operation succeeds. The default value is [Done].

failure

The string to replace the indicator with when the operation fails: The default value is [Failed].

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(frames: ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"])

background {
    // complete the indicator after 3 seconds
    console.wait(seconds: 3)
    indicator.succeed()
}
// start the indicator and wait for it to finish
try indicator.start(on: ...).wait()

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