CocoaPods trunk is moving to be read-only. Read more on the blog, there are 13 months to go.
| TestsTested | ✗ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Sep 2017 |
| SwiftSwift Version | 3.0 |
| SPMSupports SPM | ✓ |
Maintained by Michał Tynior.
Terminal string styling for Swift.
You can use The Swift Package Manager to install ColorizeSwift by adding it to your Package.swift file:
import PackageDescription
let package = Package(
name: "MyApp",
targets: [],
dependencies: [
.Package(url: "https://github.com/mtynior/ColorizeSwift.git", majorVersion: 1)
]
)You can also manually add ColorizeSwift to you project:
ColorizeSwift.swift file,ColorizeSwift.swift into you project’s tree.You can run sample application:
Example folder../build.sh script to build sample application../example pacman to launch sample.Available samples:
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() (not widely supported) underline()reverse()hidden()strikethrough() (not widely supported) 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()You can also use 256 colors, but keep in mind that not all Terminal clients support them.
foregroundColor(color: TerminalColor)backgroundColor(color: TerminalColor)colorize(foreground: TerminalColor, background: TerminalColor)You can access 256 colors using TerminalColor enumeration.
Sometimes you only need the open code for a modifier. You can access them using TerminalStyle enum:
TerminalStyle.bold.open // "\u{001B}[1m"
TerminalStyle.bold.close // "\u{001B}[22m"For 256 colors use:
TerminalColor.red.foregroundStyleCode().open \\"\u{001B}[38;5;9m"
TerminalColor.red.backgroundStyleCode().open \\"\u{001B}[48;5;9m"Colorization can be disabled globally:
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 is released under the MIT license. See LICENSE for details.