Latest 1.1.0
Homepage https://github.com/mtynior/ColorizeSwift
License MIT
Platforms ios 9.0, osx 10.10, tvos 9.0, watchos 2.0, requires ARC
Authors

ColorizeSwift

Swift 3.0
License
CocoaPods
Carthage

Terminal string styling for Swift.

Requirements

  • iOS 9.0+ / Mac OS X 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8.0+

Integration

CocoaPods

You can use CocoaPods to install ColorizeSwift by adding it to your Podfile:

platform :ios, '9.0'
use_frameworks!

target 'MyApp' do
    pod 'ColorizeSwift'
end

Run pods install to intagrate pods with your project.

Carthage

You can use Carthage to install ColorizeSwift by adding it to your Cartfile:

github "mtynior/ColorizeSwift"

Run carthage update to build the framework and drag the built ColorizeSwift.framework into your Xcode project.

Swift Package Managers (SPM)

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)
    ]
)

Manually

You can also manually add ColorizeSwift to you project:

  1. Download ColorizeSwift.swift file,
  2. Drag ColorizeSwift.swift into you project’s tree.

Example

You can run sample application:

  1. Open Terminal and go to Example folder.
  2. Run ./build.sh script to build sample application.
  3. Run ./example pacman to launch sample.

Available samples:

  1. styles – prints available styles

    Example - Styles

  2. f1 – prints F1 cars

    Example - F1

  3. pacman – prints Pacman

    Example - Pacman

  4. mario – prints mario

    Example - Mario

Usage

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())

Styles

Modifiers

  • bold()
  • dim()
  • italic() (not widely supported)
  • underline()
  • reverse()
  • hidden()
  • strikethrough() (not widely supported)
  • reset()

Foreground colors

  • black()
  • red()
  • green()
  • yellow()
  • blue()
  • magenta()
  • cyan()
  • lightGray()
  • darkGray()
  • lightRed()
  • lightGreen()
  • lightYellow()
  • lightBlue()
  • lightMagenta()
  • lightCyan()
  • white()

Background colors

  • onBlack()
  • onRed()
  • onGreen()
  • onYellow()
  • onBlue()
  • onMagenta()
  • onCyan()
  • onLightGray()
  • onDarkGray()
  • onLightRed()
  • onLightGreen()
  • onLightYellow()
  • onLightBlue()
  • onLightMagenta()
  • onLightCyan()
  • onWhite()

256-colors

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)

Available colors

You can access 256 colors using TerminalColor enumeration.

256 Colors

Escape codes

Sometimes you need only 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"

License

ColorizeSwift is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "ColorizeSwift",
    "version": "1.1.0",
    "summary": "Terminal string styling for Swift",
    "homepage": "https://github.com/mtynior/ColorizeSwift",
    "license": "MIT",
    "authors": {
        "Michau0142 Tynior": "[email protected]"
    },
    "social_media_url": "http://twitter.com/mtynior",
    "platforms": {
        "ios": "9.0",
        "osx": "10.10",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "source": {
        "git": "https://github.com/mtynior/ColorizeSwift.git",
        "tag": "1.1.0"
    },
    "source_files": "Source/*.swift",
    "requires_arc": true,
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This