Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luoxiu/Chalk
✏️Expressive styling on terminal string. (chalk for swift)
https://github.com/luoxiu/Chalk
chalk cli color swift terminal
Last synced: 3 months ago
JSON representation
✏️Expressive styling on terminal string. (chalk for swift)
- Host: GitHub
- URL: https://github.com/luoxiu/Chalk
- Owner: luoxiu
- License: mit
- Created: 2018-10-19T04:26:56.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-11-17T06:14:23.000Z (almost 4 years ago)
- Last Synced: 2024-08-04T00:06:24.573Z (3 months ago)
- Topics: chalk, cli, color, swift, terminal
- Language: Swift
- Homepage:
- Size: 232 KB
- Stars: 58
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Crayon - Terminal string styling with expressive api and 256/TrueColor support. (Command Line / Linter)
README
# 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](https://github.com/chalk/chalk) -- one of the most popular packages on npm.
```swift
print(chalk.cyan.on("cyan")) // `ck` is an alias to `chalk`// chainable
print(ck.red.bgBlue.italic.underline.on("red bgBlue italic underline"))// combine terminal string and string
print(ck.red.on("ERROR") + " something went wrong. " + ck.green.on("but no worry! I will..."))// rgb & hsl & hsv & hex support
print(ck.fg(.rgb(0, 92, 197)).bg(.hex(0xFA4B8B)).on("meow"))// custom foreground color and background color with 100+ handpicked colors
print(ck.fg(.darkMagenta).bg(.lightGoldenRodYellow).bold.on("hi"))// nest
print(ck.magenta.underline.on("begin" + ck.red.bold.on("important") + "end"))
print(ck.magenta.underline.on("begin", ck.red.bold.on("important"), "end"))
```## Styles
### Modifiers
```swift
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
The powerful color system is built on [Rainbow](https://github.com/luoxiu/Rainbow).
#### Ansi16
```swift
// with `bg` prefix will set background colorblack
red
green
yellow
blue
magenta
cyan
whiteblackBright
redBright
greenBright
yellowBright
blueBright
magentaBright
cyanBright
whiteBright
```#### 256/TrueColoe
```swift
ck.fg(.rgb(0, 100, 200))
ck.fg(.hsl(300, 50, 50))
ck.fg(.hsv(300, 50, 50))
ck.bg(.hex(0x123456))
ck.bg(.hex("#123456")
ck.bg(.hex("#abc")
```#### Built-in 100+ beautiful colors
```swift
let color = Color.Material.red50
let color = Color.Material.purple500
let color = Color.CSS.navy
let color = Color.CSS.tomatock.fg(color)
ck.bg(color)
//...
```## Install
```swift
dependencies: [
.package(url: "https://github.com/luoxiu/Chalk", from: "0.2.0")
]
``````ruby
pod 'Chalk', '~> 0.2.0'
```## Acknowledge
Inspired by the awesome javascript library [chalk](https://github.com/chalk/chalk).
## Related
- [Rainbow](https://github.com/luoxiu/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!