Skip to content
Swift cli spinner. Simple and fully customizable.
Swift
Branch: master
Clone or download
Latest commit ec165db Jul 1, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Assets Initial commit May 21, 2018
Sources Use public instead of open for let variables Jul 1, 2018
.gitignore Initial commit May 21, 2018
LICENSE Initial commit May 21, 2018
Package.resolved Update ANSIEscapeCode May 23, 2018
Package.swift
README.md

README.md

Motor
GitHub release Swift Package Manager license

Swift cli spinner. Simple and fully customizable.

Table of Contents

Demo

import Foundation
import Motor

/// Initialize spinner.
let spinner = Spinner(pattern: Patterns.dots)
/// Start spinner.
spinner.start(message: "Motor initiated...")
/// Do your job.
sleep(2)
/// Print message.
spinner.display("Do something...")
/// Do another job.
sleep(3)
/// Stop spinner with message.
spinner.stop(message: "".color(.green) + " Done!")

On terminal

Demo

Installation

Add Motor to Package.swift.

dependencies: [
    .package(url: "https://github.com/flintbox/Motor", from: "0.1.1")
]

Customization

Pattern

public struct Pattern {

    public let frames: [String]
    public let fps: UInt32
}

Spinner pattern. frames for frames of the animation. fps(frames per second) for frame rate.

Delay

open class Animator: Operation {

    public init(pattern: Pattern, delay: UInt32) {
        spinner = Animation(pattern: pattern)
        self.delay = delay
        super.init()
    }
}

Delay before starting animation. Useful when duration of the job could be short and don't want to flash spinner.

Message

open class Spinner {

    open func start(message: String = "") {
    }

    open func display(_ message: String) {
    }

    open func stop(message: String? = nil) {
    }
}

On start, during or termination of the animation. Show message beside spinner. Please, keep in mind that the spinner and message should be in one line to be correctly animated.

Contribute

If you have good idea or suggestion? Please, don't hesitate to open a pull request or send me an email.

Hope you enjoy building command line tool with Motor!

You can’t perform that action at this time.