Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flintprocessor/motor
Swift cli spinner. Simple and fully customizable.
https://github.com/flintprocessor/motor
cli spinner swift swift-package-manager
Last synced: 2 months ago
JSON representation
Swift cli spinner. Simple and fully customizable.
- Host: GitHub
- URL: https://github.com/flintprocessor/motor
- Owner: flintprocessor
- License: mit
- Created: 2018-05-21T16:16:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-01T06:46:38.000Z (over 6 years ago)
- Last Synced: 2024-10-30T17:16:27.134Z (3 months ago)
- Topics: cli, spinner, swift, swift-package-manager
- Language: Swift
- Homepage:
- Size: 112 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Motor
*Swift cli spinner. **Simple** and **fully customizable**.*
**Table of Contents**
- [Demo](#demo)
- [Installation](#installation)
- [Customization](#customization)
- [Pattern](#pattern)
- [Delay](#delay)
- [Message](#message)
- [Contribute](#contribute)## [Demo](https://github.com/flintbox/Motor/blob/master/Sources/motor-example/main.swift)
```swift
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](Assets/demo.gif)
## Installation
Add Motor to `Package.swift`.
```swift
dependencies: [
.package(url: "https://github.com/flintbox/Motor", from: "0.1.1")
]
```## Customization
### [Pattern](https://github.com/flintbox/Motor/blob/master/Sources/Motor/Pattern.swift)
```swift
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](https://github.com/flintbox/Motor/blob/master/Sources/Motor/Animator.swift)
```swift
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](https://github.com/flintbox/Motor/blob/master/Sources/Motor/Spinner.swift)
```swift
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](mailto:[email protected]).
Hope you enjoy building command line tool with Motor!