Skip to content

Instantly share code, notes, and snippets.

@cprovatas
Created June 8, 2019 22:56
Show Gist options
  • Select an option

  • Save cprovatas/d8d1729fe8621c35b46acf463cd091d3 to your computer and use it in GitHub Desktop.

Select an option

Save cprovatas/d8d1729fe8621c35b46acf463cd091d3 to your computer and use it in GitHub Desktop.

Revisions

  1. cprovatas created this gist Jun 8, 2019.
    19 changes: 19 additions & 0 deletions interpolation.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    enum ASCIIColor: String {
    case black = "\u{001B}[0;30m"
    case red = "\u{001B}[0;31m"
    case green = "\u{001B}[0;32m"
    case yellow = "\u{001B}[0;33m"
    case blue = "\u{001B}[0;34m"
    case magenta = "\u{001B}[0;35m"
    case cyan = "\u{001B}[0;36m"
    case white = "\u{001B}[0;37m"
    case `default` = "\u{001B}[0;0m"
    }

    extension DefaultStringInterpolation {
    mutating func appendInterpolation<T: CustomStringConvertible>(_ value: T, color: ASCIIColor) {
    appendInterpolation("\(color.rawValue)\(value)\(ASCIIColor.default.rawValue)")
    }
    }
    // USAGE:
    // "\("only this string will be green!", color: .green)"