Swifty Terminal Spinner
Switch branches/tags
Nothing to show
Clone or download
Latest commit 93ca0c5 Jul 28, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Sources/CLISpinner explicitly import dispatch Aug 10, 2017
Tests such test, much wow Aug 2, 2017
.gitignore initial commit Aug 1, 2017
.travis.yml only build on travis Aug 2, 2017
LICENSE add MIT license Aug 1, 2017
Package.resolved bump rainbow version Jul 28, 2018
Package.swift bump rainbow version Jul 28, 2018
README.md Improve display of sigint keyboard shortcut May 5, 2018

README.md

CLISpinner

Travis

60+ spinners for use in the terminal

Shamelessly ripped off from sindresorhus/cli-spinners.

Install

.package(url: "https://github.com/kiliankoe/CLISpinner", from: "see latest release")

Usage

Just want to display a simple spinner for two seconds?

let s = Spinner(pattern: .dots)
s.start()
sleep(2)
s.stop()

Want some changing text and patterns?

let s = Spinner(pattern: .dots, text: "Foobar...", color: .lightCyan)
s.start()
sleep(2)
s.succeed(text: "Barfoo")
// will change the displayed text to '✔ Barfoo'

That's basically it 👌

Caveat

To look nice the spinner hides the user's cursor as long as it's running and displays it again when stopped. The issue with this is that the cursor will still be hidden if the user interrupts the process (by sending a SIGINT through ctrl+c for example). The best way to handle this is by setting up a signal handler in your code and calling spinner.unhideCursor() on exiting. This library purposefully does not do that for you so as not to interfere with any possible signal handlers you might already have set up.

See IBM-Swift/BlueSignals for a clean and safe way of handling signals. The appropriate signal handler for your project could look something like this.

import Signals

let spinner = Spinner(pattern: .dots)
// ...

Signals.trap(signal: .int) { _ in
    spinner.unhideCursor()
    exit(0)
}

Used by