🖍 Expressive styling on terminal string. (chalk for swift)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Sources/Crayon Fix nest closing issue. Nov 5, 2018
Tests Fix nest closing issue. Nov 5, 2018
.gitignore hi Nov 1, 2018
.travis.yml Add travis support Nov 3, 2018
LICENSE
Package.resolved Support 256 and 16m Nov 3, 2018
Package.swift Support 256 and 16m Nov 3, 2018
README.md Fix nest closing issue. Nov 5, 2018
crayon.jpg Multiple parameters Nov 4, 2018

README.md

Crayon





Expressive styling on terminal string.

Highlights

  • Expressive API
  • 256/TrueColor support
  • Nestable
  • Auto downgrading to terminal color support level
  • No extensions on String
  • Built-in 100+ handpicked colors
  • rgb & hsl & hsv & hex

Usage

Crayon's API is very similar to chalk -- one of the most popular packages on npm, it's clean and focused.

print(crayon.cyan.on("cyan"))  // `cy` is an alias to `crayon`

// chainable
print(cy.red.bgMagenta.bold.underline.on("red bgMagenta bild underline"))

// combine terminal string and normal string
print(cy.red.on("!") + "error" + cy.green.on("o"))

// custom foreground color and background color with 100+ handpicked colors
print(cy.fg(.coral).bg(.lightGreen).bold.on("hi"))

// rgb & hsl & hsv & hex support
print(cy.fg(.rgb(0, 92, 197)).bg(.hex(0xf6f8fa)).underline.on("meow"))

// nestable
print(cy.bgYellow.on("begin" + cy.red.bold.on("important") + "end"))
print(cy.bgYellow.on("begin", cy.red.bold.on("important"), "end"))


// define your own delightful output
let warn = { (s: String) in
    print(cy.white.bgYellow.on(s))
}
let error = { (s: String) in
    print(cy.red.bold.on(s))
}

warn("this is a warning!")
error("something wrong!")

Styles

Modifiers

reset
bold
faint              // aka dim, not widely supported.
italic
underline
blink
reverse
conceal            // aka hidden, not widely supported.
crossedOut         // aka strikethrough, not widely supported.

Colors

Ansi16

// with `bg` prefix will set background color

black
red
green
yellow
blue
magenta
cyan
white

blackBright
redBright
greenBright
yellowBright
blueBright
magentaBright
cyanBright
whiteBright

256/TrueColoe

cy.fg(.rgb(0, 100, 200))
cy.fg(.hsl(300, 50, 50))
cy.fg(.hsv(300, 50, 50))
cy.bg(.hex(0x123456))
cy.bg(.hex("#abc")
cy.bg(.hex("#123456")

100+ handpicked colors

cy.fg(.peachpuff)
cy.fg(.plum)
cy.bg(.coral)
cy.bg(.fuchsia)
//...

Install

dependencies: [
    .package(url: "https://github.com/jianstm/Crayon", .upToNextMajor(from: "0.0.1"))
]

Acknowledge

Inspired by the awesome javascript library chalk.

Related

  • Rainbow - 🌈 Color conversion and manipulation library for Swift with no dependence on UIKit/AppKit.

Contribute

If you find a bug, open an issue, if you want to add new features, feel free to submit a pull request. Any contributing is welcome at all times!