项目作者: luoxiu

项目描述 :
✏️Expressive styling on terminal string. (chalk for swift)
高级语言: Swift
项目地址: git://github.com/luoxiu/Chalk.git
创建时间: 2018-10-19T04:26:56Z
项目社区:https://github.com/luoxiu/Chalk

开源协议:MIT License

下载


Chalk












Expressive styling on terminal string.

Highlights

  • Expressive API
  • 256/TrueColor support
  • Nest styles
  • Auto downgrading to terminal supported color
  • No extensions on String
  • rgb & hsl & hsv & hex
  • Built-in 100+ beautiful colors

Usage

Chalk’s API is very similar to chalk — one of the most popular packages on npm.

  1. print(chalk.cyan.on("cyan")) // `ck` is an alias to `chalk`
  2. // chainable
  3. print(ck.red.bgBlue.italic.underline.on("red bgBlue italic underline"))
  4. // combine terminal string and string
  5. print(ck.red.on("ERROR") + " something went wrong. " + ck.green.on("but no worry! I will..."))
  6. // rgb & hsl & hsv & hex support
  7. print(ck.fg(.rgb(0, 92, 197)).bg(.hex(0xFA4B8B)).on("meow"))
  8. // custom foreground color and background color with 100+ handpicked colors
  9. print(ck.fg(.darkMagenta).bg(.lightGoldenRodYellow).bold.on("hi"))
  10. // nest
  11. print(ck.magenta.underline.on("begin" + ck.red.bold.on("important") + "end"))
  12. print(ck.magenta.underline.on("begin", ck.red.bold.on("important"), "end"))

Styles

Modifiers

  1. reset
  2. bold
  3. faint // aka dim, not widely supported.
  4. italic
  5. underline
  6. blink
  7. reverse
  8. conceal // aka hidden, not widely supported.
  9. crossedOut // aka strikethrough, not widely supported.

Colors

The powerful color system is built on Rainbow.

Ansi16

  1. // with `bg` prefix will set background color
  2. black
  3. red
  4. green
  5. yellow
  6. blue
  7. magenta
  8. cyan
  9. white
  10. blackBright
  11. redBright
  12. greenBright
  13. yellowBright
  14. blueBright
  15. magentaBright
  16. cyanBright
  17. whiteBright

256/TrueColoe

  1. ck.fg(.rgb(0, 100, 200))
  2. ck.fg(.hsl(300, 50, 50))
  3. ck.fg(.hsv(300, 50, 50))
  4. ck.bg(.hex(0x123456))
  5. ck.bg(.hex("#123456")
  6. ck.bg(.hex("#abc")

Built-in 100+ beautiful colors

  1. let color = Color.Material.red50
  2. let color = Color.Material.purple500
  3. let color = Color.CSS.navy
  4. let color = Color.CSS.tomato
  5. ck.fg(color)
  6. ck.bg(color)
  7. //...

Install

  1. dependencies: [
  2. .package(url: "https://github.com/luoxiu/Chalk", from: "0.2.0")
  3. ]
  1. pod 'Chalk', '~> 0.2.0'

Acknowledge

Inspired by the awesome javascript library chalk.

  • 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!