Skip to content
/ Chalk Public

✏️Expressive styling on terminal string. (chalk for swift)

License

Notifications You must be signed in to change notification settings

luoxiu/Chalk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crayon





Expressive styling on terminal string.

Highlights

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

Usage

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

print(cy.red.bgBlue.on("red bgBlue"))

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

print(cy.fg(.coral).bg(.lightGreen).bold.on("coral lightGreen bold"))

print(cy.fg(.rgb(0, 92, 197)).bg(.hex(0xf6f8fa)).bold.on("hello"))

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


let warn = { (s: String) in
	return cy.white.bgYellow.on(s)
}
let error = { (s: String) in
	return cy.red.bold.on(s)
}
print(warn("this is a warning!"))
print(error("something wrong!")

Styles

Modifiers

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

Colors

Ansi16

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")

Install

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

Contribute

If you want to add new features, feel free to submit a pull request. Any contributing is welcome at all times!

Acknowledge

Inspired by the awesome javascript library chalk.