使用 Swift 5 字符串插值扩展的终端颜色。
import Chalk // @mxcl ~> 0.3
let colorString = "blue"
print("Here’s \(colorString, color: .blue)!")
// 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")
Chalk 由 @sindresorhus 开发,是一个非常著名的同用途 Node 包。开源社区通过名称联系更容易推广,我们选择相同的名称是为了建立这些心智联系。
这个包被称为 Chalk,或者 mxcl/Chalk
,或者在需要区分时称为 Swift 版 Chalk。
大家好,我是 Max Howell,一位多产的开源贡献者,可能你已经在使用我的一些开源项目了(brew
就是我创建的)。我全职从事开源工作,这很辛苦;目前 *我的收入低于最低工资标准*。请帮助我继续我的工作,非常感谢 🙏🏻
如果你安装了 swift-sh
$ swift sh <<EOF
import Foundation
import Chalk // @mxcl ~> 0.3
for 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
将会显示
SwiftPM
package.append(.package(url: "https://github.com/mxcl/Chalk.git", from: "0.1.0"))
Carthage
等待:@Carthage#1945。