Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mxcl/chalk
Terminal colors using Swift 5’s string interpolation extensions.
https://github.com/mxcl/chalk
swift terminal-colors
Last synced: 21 days ago
JSON representation
Terminal colors using Swift 5’s string interpolation extensions.
- Host: GitHub
- URL: https://github.com/mxcl/chalk
- Owner: mxcl
- License: unlicense
- Created: 2019-02-20T21:47:00.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-22T11:50:45.000Z (9 months ago)
- Last Synced: 2024-04-14T10:47:42.043Z (7 months ago)
- Topics: swift, terminal-colors
- Language: Swift
- Homepage:
- Size: 886 KB
- Stars: 217
- Watchers: 6
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chalk
Terminal colors using Swift 5’s string interpolation extensions.
```swift
import Chalk // @mxcl ~> 0.3let colorString = "blue"
print("Here’s \(colorString, color: .blue)!")
```# Styles, Backgrounds, Extended Colors etc.
```swift
// color, background & style can be specified all together or individually:
print("Foo \(string, color: .blue) bar")
print("Foo \(string, color: .blue, background: .yellow) bar")
print("Foo \(string, color: .blue, background: .yellow, style: .underline) bar")// styles are an `OptionSet`:
print("Foo \(string, style: .underline) bar")
print("Foo \(string, style: [.underline, .bold]) bar")// 256 color mode is supported:
print("Foo \(string, color: .extended(78) bar")
```# Name
[Chalk] by [@sindresorhus] is an extremely famous Node package for the same
purpose. Open source is facilitated by naming connections, we picked the same
name to enable those mental connections.This package is called Chalk, or `mxcl/Chalk` or Chalk for Swift when
disambiguating.[@sindresorhus]: https://github.com/sindresorhus
[Chalk]: https://github.com/chalk/chalk# Support mxcl
Hey there, I’m Max Howell, a prolific producer of open source and probably you
already use some of it (I created [`brew`]). I work full-time on open source and
it’s hard; currently *I earn less than minimum wage*. Please help me continue my
work, I appreciate it 🙏🏻[Other ways to say thanks](http://mxcl.dev/#donate).
[`brew`]: https://brew.sh
# Demo
If you have [`swift-sh`]:
```
$ swift sh < 0.3for x in 0..<256 {
let cell = " \(x)".padding(toLength: 5, withPad: " ", startingAt: 0)
let terminator = (x + 3).isMultiple(of: 6) ? "\n" : ""
print("\(cell, color: .extended(15), background: .extended(UInt8(x)))", terminator: terminator)
}
EOF
```Will give you:
[`swift-sh`]: https://github.com/mxcl/swift-sh
# Installation
SwiftPM:
```swift
package.append(.package(url: "https://github.com/mxcl/Chalk.git", from: "0.1.0"))
```Carthage:
> Waiting on: [@Carthage#1945](https://github.com/Carthage/Carthage/pull/1945).