Swiftpack.co - jordanbaird/Prism as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by jordanbaird.
jordanbaird/Prism 0.0.4
Colored text for Swift command line tools.
⭐️ 7
🕓 3 weeks ago
.package(url: "https://github.com/jordanbaird/Prism.git", from: "0.0.4")


Continuous Integration Code Coverage Release Swift Version License

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



Add the following dependency to your Package.swift file:

.package(url: "https://github.com/jordanbaird/Prism", from: "0.0.4")


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 {
    ForegroundColor(.green, "This text's color is green.")
    Bold("This text is bold.")
    Italic("This text is italic.")
    Underline("This text is underlined.")
    Strikethrough("This text has a strikethrough.")

Each attribute functions similarly to Prism itself, in that you can nest other elements inside of them. The String type conforms to PrismElement, so you can use string literals inline with other elements and attributes.

let prism = Prism {
    Bold {
        "This text is bold."
        Italic {
            "This text is bold and italic."
        Underline("This text is bold and underlined.")
        BackgroundColor(.cyan) {
            Underline {
                "This text is bold, underlined, and has a cyan background."

The Prism type can be directly used in a print() function, and the formatted string will be printed directly to the terminal or console. If the terminal or console does not support formatted text, the unformatted version of the string will be printed instead.

NOTE: 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 that Prism provides it.


Stars: 7
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Prism 0.0.4
3 weeks ago

This release fixes a memory issue, and is recommended for all users.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics