Prism

Continuous Integration Release Swift License

Prism is a simple DSL that uses declarative syntax to create beautiful formatted text for Swift command line tools. While it is meant to be easy to use, it is also quite powerful. It works on both macOS and Linux.

Install

Add the following to your Package.swift file:

import PackageDescription
let package = Package(
    name: "PackageName",
    dependencies: [
        .package(url: "https://github.com/jordanbaird/Prism", from: "0.0.1")
    ],
    targets: [
        .target(
            name: "PackageName",
            dependencies: ["Prism"]
        )
    ]
)

Usage

Read the full documentation here

Start by creating an instance of the Prism type. Its initializer accepts a closure, which you populate with various attributes.

let prism = Prism(spacing: .managed(.lineBreaks)) {
    ForegroundColor(.green, "This text's foreground is green.")
    BackgroundColor(.blue, "This text's background is blue.")
    Bold("This text is bold.")
    Dim("This text is dim.")
    Italic("This text is italic.")
    Underline("This text is underlined.")
    Blink("This text blinks.")
    Swap("This text has its foreground and background colors swapped.")
    Strikethrough("This text has a strikethrough.")
}
print(prism)

The result will look something like this:

Each attribute functions similarly to Prism itself, in that you can nest other elements inside of them.

Things may show up differently, depending on which terminal client is being used. It is up to the terminal to determine how it will display the control codes Prism provides it.

GitHub

View Github