A Swift wrapper for Console I/O.
- Terminal Colors
- User Input
- Threads and Animations
Create a terminal console, or create a new type of console that conforms to the Console
protocol.
let console = Terminal()
let name = console.ask("What is your name?")
console.print("Hello, \(name).")
if console.confirm("Are you sure?") {
// user is sure
}
console.warning("Watch out!")
public enum ConsoleStyle {
case plain
case success
case info
case warning
case error
case custom(ConsoleColor)
}
console.output("Cool colors.", style: .custom(.magenta))
public enum ConsoleColor {
case black
case red
case green
case yellow
case blue
case magenta
case cyan
case white
}
For showing loading with progress updates.
let filename = "filename.txt"
let progressBar = console.progressBar(title: filename)
progress.start()
fakeClient.download(progressCallback: { progress in
progressBar.progress = progress
}, completionCallback: { file in
progressBar.finish()
})
filename.txt [==== ] 23%
For showing loading of indeterminate length.
let filename = "filename.txt"
let loadingBar = console.loadingBar(title: "Connecting")
loadingBar.start()
fakeServer.connect(completionCallback: { connection in
loadingBar.finish()
})
Connecting [ • ]
Travis builds this package on both Ubuntu 14.04 and macOS 10.11. Check out the .travis.yml
file to see how this package is built and compiled during testing.
This wrapper was created to power Vapor, a Web Framework for Swift.
Created by Tanner Nelson.