0001    //
0002    //  StringStyle.swift
0003    //  StringStyle
0004    //
0005    //  Created by Omar Abdelhafith on 31/10/2015.
0006    //  Copyright © 2015 Omar Abdelhafith. All rights reserved.
0007    //
0008    
0009    import Foundation
0010    
0011    
0012    let startOfCode
StringStyle.swift:49
        return "\(startOfCode)\(color)\(endOfCode)"
StringStyle.swift:53
        return string.containsString(startOfCode)
StringStyle.swift:59
        let newString = string.stringByReplacingOccurrencesOfString(startOfCode, withString: ";", options: .LiteralSearch, range: rangeWithInset)
= "\u{001B}[" 0013 let endOfCode
StringStyle.swift:49
        return "\(startOfCode)\(color)\(endOfCode)"
= "m" 0014 let codesSeperators = ";" 0015 0016 0017 protocol StringStyle
Colorizer.swift:48
    let color: StringStyle
Colorizer.swift:51
    init(string: String, color: StringStyle) {
StringStyle.swift:23
extension StringStyle {
StringStyle.swift:76
enum ForegroundColor: Int, StringStyle {
StringStyle.swift:89
enum BackgroundColor: Int, StringStyle {
StringStyle.swift:102
enum StringTextStyle: Int, StringStyle {
{ 0018 var rawValue
StringStyle.swift:35
        return "\(preparedColorCode(self.rawValue))\(string)\(endingColorCode())"
StringStyle.swift:41
        let sringwWithStart = "\(preparedColorCode(self.rawValue))\(stringByRemovingEnding)"
: Int { get } 0019 func colorize
Colorizer.swift:57
        return color.colorize(string: string)
(string string: String) -> String 0020 } 0021 0022 0023 extension StringStyle { 0024 0025 func colorize(string string: String) -> String { 0026 0027 if hasAnyStyleCode(string) { 0028 return colorizeStringAndAddCodeSeperators(string) 0029 } else { 0030 return colorizeStringWithoutPriorCode(string) 0031 } 0032 } 0033 0034 private func colorizeStringWithoutPriorCode
StringStyle.swift:30
            return colorizeStringWithoutPriorCode(string)
(string: String) -> String { 0035 return "\(preparedColorCode(self.rawValue))\(string)\(endingColorCode())" 0036 } 0037 0038 private func colorizeStringAndAddCodeSeperators
StringStyle.swift:28
            return colorizeStringAndAddCodeSeperators(string)
(string: String) -> String { 0039 //To refactor and use regex matching instead of replacing strings and using tricks 0040 let stringByRemovingEnding = removeEndingCode(string) 0041 let sringwWithStart = "\(preparedColorCode(self.rawValue))\(stringByRemovingEnding)" 0042 0043 let stringByAddingCodeSeperator = addCommandSeperators(sringwWithStart) 0044 0045 return "\(stringByAddingCodeSeperator)\(endingColorCode())" 0046 } 0047 0048 private func preparedColorCode
StringStyle.swift:35
        return "\(preparedColorCode(self.rawValue))\(string)\(endingColorCode())"
StringStyle.swift:41
        let sringwWithStart = "\(preparedColorCode(self.rawValue))\(stringByRemovingEnding)"
StringStyle.swift:71
        return preparedColorCode(0)
(color: Int) -> String { 0049 return "\(startOfCode)\(color)\(endOfCode)" 0050 } 0051 0052 private func hasAnyStyleCode
StringStyle.swift:27
        if hasAnyStyleCode(string) {
(string: String) -> Bool { 0053 return string.containsString(startOfCode) 0054 } 0055 0056 private func addCommandSeperators
StringStyle.swift:43
        let stringByAddingCodeSeperator = addCommandSeperators(sringwWithStart)
(string: String) -> String { 0057 0058 var rangeWithInset = Range(start: string.startIndex.successor(), end: string.endIndex.predecessor()) 0059 let newString = string.stringByReplacingOccurrencesOfString(startOfCode, withString: ";", options: .LiteralSearch, range: rangeWithInset) 0060 0061 rangeWithInset = Range(start: newString.startIndex.successor(), end: newString.endIndex.predecessor()) 0062 return newString.stringByReplacingOccurrencesOfString("m;", withString: ";", options: .LiteralSearch, range: rangeWithInset) 0063 } 0064 0065 private func removeEndingCode
StringStyle.swift:40
        let stringByRemovingEnding = removeEndingCode(string)
(string: String) -> String { 0066 let rangeWithInset = Range(start: string.startIndex.successor(), end: string.endIndex) 0067 return string.stringByReplacingOccurrencesOfString(endingColorCode(), withString: "", options: .LiteralSearch, range: rangeWithInset) 0068 } 0069 0070 private func endingColorCode
StringStyle.swift:35
        return "\(preparedColorCode(self.rawValue))\(string)\(endingColorCode())"
StringStyle.swift:45
        return "\(stringByAddingCodeSeperator)\(endingColorCode())"
StringStyle.swift:67
        return string.stringByReplacingOccurrencesOfString(endingColorCode(), withString: "", options: .LiteralSearch, range: rangeWithInset)
() -> String { 0071 return preparedColorCode(0) 0072 } 0073 } 0074 0075 0076 enum ForegroundColor
StringForegroundColorizer.swift:17
            return Colorizer(string: string, color: ForegroundColor.Black).description
StringForegroundColorizer.swift:21
            return Colorizer(string: string, color: ForegroundColor.Red).description
StringForegroundColorizer.swift:25
            return Colorizer(string: string, color: ForegroundColor.Green).description
StringForegroundColorizer.swift:29
            return Colorizer(string: string, color: ForegroundColor.Yellow).description
StringForegroundColorizer.swift:33
            return Colorizer(string: string, color: ForegroundColor.Blue).description
StringForegroundColorizer.swift:37
            return Colorizer(string: string, color: ForegroundColor.Magenta).description
StringForegroundColorizer.swift:41
            return Colorizer(string: string, color: ForegroundColor.Cyan).description
StringForegroundColorizer.swift:45
            return Colorizer(string: string, color: ForegroundColor.White).description
: Int, StringStyle { 0077 0078 case Black
StringForegroundColorizer.swift:17
            return Colorizer(string: string, color: ForegroundColor.Black).description
= 30 0079 case Red
StringForegroundColorizer.swift:21
            return Colorizer(string: string, color: ForegroundColor.Red).description
= 31 0080 case Green
StringForegroundColorizer.swift:25
            return Colorizer(string: string, color: ForegroundColor.Green).description
= 32 0081 case Yellow
StringForegroundColorizer.swift:29
            return Colorizer(string: string, color: ForegroundColor.Yellow).description
= 33 0082 case Blue
StringForegroundColorizer.swift:33
            return Colorizer(string: string, color: ForegroundColor.Blue).description
= 34 0083 case Magenta
StringForegroundColorizer.swift:37
            return Colorizer(string: string, color: ForegroundColor.Magenta).description
= 35 0084 case Cyan
StringForegroundColorizer.swift:41
            return Colorizer(string: string, color: ForegroundColor.Cyan).description
= 36 0085 case White
StringForegroundColorizer.swift:45
            return Colorizer(string: string, color: ForegroundColor.White).description
= 37 0086 } 0087 0088 0089 enum BackgroundColor
StringBackgroundColorizer.swift:17
            return Colorizer(string: string, color: BackgroundColor.Black).description
StringBackgroundColorizer.swift:21
            return Colorizer(string: string, color: BackgroundColor.Red).description
StringBackgroundColorizer.swift:25
            return Colorizer(string: string, color: BackgroundColor.Green).description
StringBackgroundColorizer.swift:29
            return Colorizer(string: string, color: BackgroundColor.Yellow).description
StringBackgroundColorizer.swift:33
            return Colorizer(string: string, color: BackgroundColor.Blue).description
StringBackgroundColorizer.swift:37
            return Colorizer(string: string, color: BackgroundColor.Magenta).description
StringBackgroundColorizer.swift:41
            return Colorizer(string: string, color: BackgroundColor.Cyan).description
StringBackgroundColorizer.swift:45
            return Colorizer(string: string, color: BackgroundColor.White).description
: Int, StringStyle { 0090 0091 case Black
StringBackgroundColorizer.swift:17
            return Colorizer(string: string, color: BackgroundColor.Black).description
= 40 0092 case Red
StringBackgroundColorizer.swift:21
            return Colorizer(string: string, color: BackgroundColor.Red).description
= 41 0093 case Green
StringBackgroundColorizer.swift:25
            return Colorizer(string: string, color: BackgroundColor.Green).description
= 42 0094 case Yellow
StringBackgroundColorizer.swift:29
            return Colorizer(string: string, color: BackgroundColor.Yellow).description
= 43 0095 case Blue
StringBackgroundColorizer.swift:33
            return Colorizer(string: string, color: BackgroundColor.Blue).description
= 44 0096 case Magenta
StringBackgroundColorizer.swift:37
            return Colorizer(string: string, color: BackgroundColor.Magenta).description
= 45 0097 case Cyan
StringBackgroundColorizer.swift:41
            return Colorizer(string: string, color: BackgroundColor.Cyan).description
= 46 0098 case White
StringBackgroundColorizer.swift:45
            return Colorizer(string: string, color: BackgroundColor.White).description
= 47 0099 } 0100 0101 0102 enum StringTextStyle
StringStyleColorizer.swift:17
            return Colorizer(string: string, color: StringTextStyle.Reset).description
StringStyleColorizer.swift:21
            return Colorizer(string: string, color: StringTextStyle.Bold).description
StringStyleColorizer.swift:25
            return Colorizer(string: string, color: StringTextStyle.Italic).description
StringStyleColorizer.swift:29
            return Colorizer(string: string, color: StringTextStyle.Underline).description
StringStyleColorizer.swift:33
            return Colorizer(string: string, color: StringTextStyle.Inverse).description
StringStyleColorizer.swift:37
            return Colorizer(string: string, color: StringTextStyle.Strikethrough).description
StringStyleColorizer.swift:41
            return Colorizer(string: string, color: StringTextStyle.BoldOff).description
StringStyleColorizer.swift:45
            return Colorizer(string: string, color: StringTextStyle.ItalicOff).description
StringStyleColorizer.swift:49
            return Colorizer(string: string, color: StringTextStyle.UnderlineOff).description
StringStyleColorizer.swift:53
            return Colorizer(string: string, color: StringTextStyle.InverseOff).description
StringStyleColorizer.swift:57
            return Colorizer(string: string, color: StringTextStyle.StrikethroughOff).description
: Int, StringStyle { 0103 0104 case Reset
StringStyleColorizer.swift:17
            return Colorizer(string: string, color: StringTextStyle.Reset).description
= 0 0105 case Bold
StringStyleColorizer.swift:21
            return Colorizer(string: string, color: StringTextStyle.Bold).description
= 1 0106 case Italic
StringStyleColorizer.swift:25
            return Colorizer(string: string, color: StringTextStyle.Italic).description
= 3 0107 case Underline
StringStyleColorizer.swift:29
            return Colorizer(string: string, color: StringTextStyle.Underline).description
= 4 0108 case Inverse
StringStyleColorizer.swift:33
            return Colorizer(string: string, color: StringTextStyle.Inverse).description
= 7 0109 case Strikethrough
StringStyleColorizer.swift:37
            return Colorizer(string: string, color: StringTextStyle.Strikethrough).description
= 9 0110 case BoldOff
StringStyleColorizer.swift:41
            return Colorizer(string: string, color: StringTextStyle.BoldOff).description
= 22 0111 case ItalicOff
StringStyleColorizer.swift:45
            return Colorizer(string: string, color: StringTextStyle.ItalicOff).description
= 23 0112 case UnderlineOff
StringStyleColorizer.swift:49
            return Colorizer(string: string, color: StringTextStyle.UnderlineOff).description
= 24 0113 case InverseOff
StringStyleColorizer.swift:53
            return Colorizer(string: string, color: StringTextStyle.InverseOff).description
= 27 0114 case StrikethroughOff
StringStyleColorizer.swift:57
            return Colorizer(string: string, color: StringTextStyle.StrikethroughOff).description
= 29 0115 }