测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可 | MIT |
发布上次发布 | 2017年9月 |
SwiftSwift版本 | 3.0 |
SPM支持SPM | ✓ |
由Michał Tynior维护。
Swift的终端字符串样式。
您可以通过将ColorizeSwift添加到Package.swift文件来使用Swift Package Manager来安装ColorizeSwift
import PackageDescription
let package = Package(
name: "MyApp",
targets: [],
dependencies: [
.Package(url: "https://github.com/mtynior/ColorizeSwift.git", majorVersion: 1)
]
)
您还可以手动将ColorizeSwift添加到您的项目中
ColorizeSwift.swift
文件,ColorizeSwift.swift
拖放到项目树上。您可以运行示例应用程序
Example
文件夹。./build.sh
脚本来构建示例应用程序。./example pacman
来启动示例。可用样本
print("Normal")
print("Bold".bold())
print("Dim".dim())
print("Italic".italic())
print("Underline".underline())
print("Blink".blink())
print("Reverse".reverse())
print("hidden".hidden())
print("strikethrough".strikethrough())
print("Red".red())
print("On yellow".onYellow())
print("256 foreground".foregroundColor(.Orange1))
print("226 background".backgroundColor(.Orange1))
print("Awful combination".colorize(.Yellow, background: .Red))
let nested = "with a blue substring".blue().underline()
print("A bold, green line \(nested) that becomes bold and green again".green().bold())
bold()
dim()
italic()
(不支持广泛)underline()
reverse()
hidden()
strikethrough()
(不支持广泛)reset()
black()
red()
green()
yellow()
blue()
magenta()
cyan()
lightGray()
darkGray()
lightRed()
lightGreen()
lightYellow()
lightBlue()
lightMagenta()
lightCyan()
white()
onBlack()
onRed()
onGreen()
onYellow()
onBlue()
onMagenta()
onCyan()
onLightGray()
onDarkGray()
onLightRed()
onLightGreen()
onLightYellow()
onLightBlue()
onLightMagenta()
onLightCyan()
onWhite()
您还可以使用256色,但请注意,并非所有终端客户端都支持它们。
foregroundColor(color: TerminalColor)
backgroundColor(color: TerminalColor)
colorize(foreground: TerminalColor, background: TerminalColor)
您可以使用
有时您只需要访问修改器的开放代码
。您可以使用
TerminalStyle.bold.open // "\u{001B}[1m"
TerminalStyle.bold.close // "\u{001B}[22m"
对于256色使用
TerminalColor.red.foregroundStyleCode().open \\"\u{001B}[38;5;9m"
TerminalColor.red.backgroundStyleCode().open \\"\u{001B}[48;5;9m"
着色可以在全局范围内禁用
String.isColorizationEnabled = false // Default: true
// For example, you can support a command line option (./example --no-color)
String.isColorizationEnabled = !CommandLine.arguments.contains("--no-color")
ColorizeSwift在MIT许可证下发布。有关详细信息,请参阅LICENSE。