Created
July 25, 2017 12:14
-
-
Save MatiMax/36aa19eb395c0cec6bb685465b593a88 to your computer and use it in GitHub Desktop.
Using ANSI terminal colours — The Swift-way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
/* | |
* File: ANSITerminalColour.swift | |
* Language: Apple Swift 3 or 4 | |
* Author: Matthias M. Schneider | |
* Purpose: Demonstrate how to use an `enum` to use the ANSI colour control characters in String folding for console output. | |
* Version: 1.0 | |
* Copyright: IDC (I don't care) | |
*/ | |
enum TTY_COLOUR: String, CustomStringConvertible { | |
case red = "\u{1b}[41m " | |
case green = "\u{1b}[42m " | |
case blue = "\u{1b}[44m " | |
case bold = "\u{1b}[1m" | |
case unbold = "\u{1b}[22m" | |
case normal = " \u{1b}[0m" | |
var description: String { | |
return self.rawValue | |
} | |
} | |
print("\(TTY_COLOUR.green)This is \(TTY_COLOUR.bold)cool\(TTY_COLOUR.unbold).\(TTY_COLOUR.normal)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment