github.com/qutheory/console

💻 APIs for creating interactive CLI tools.


Keywords
command-line, console, hacktoberfest, server-side-swift, swift, swift-linux, vapor
License
MIT

Documentation

Swift Console

Swift Build Status

A Swift wrapper for Console I/O.

  • Terminal Colors
  • User Input
  • Threads and Animations

Example

Create a terminal console, or create a new type of console that conforms to the Console protocol.

let console = Terminal()

Ask

let name = console.ask("What is your name?")

console.print("Hello, \(name).")

Confirm

if console.confirm("Are you sure?") {
    // user is sure 
}

Styles

console.warning("Watch out!")
public enum ConsoleStyle {
    case plain
    case success
    case info
    case warning
    case error
    case custom(ConsoleColor)
}

Colors

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
}

Progress Bar

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%

Loading Bar

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

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.

Vapor

This wrapper was created to power Vapor, a Web Framework for Swift.

Author

Created by Tanner Nelson.