0001 // 0002 // StringGenerator.swift 0003 // Rainbow 0004 // 0005 // Created by Wei Wang on 15/12/23. 0006 // 0007 // Copyright (c) 2015 Wei Wang <onevcat@gmail.com> 0008 // 0009 // Permission is hereby granted, free of charge, to any person obtaining a copy 0010 // of this software and associated documentation files (the "Software"), to deal 0011 // in the Software without restriction, including without limitation the rights 0012 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0013 // copies of the Software, and to permit persons to whom the Software is 0014 // furnished to do so, subject to the following conditions: 0015 // 0016 // The above copyright notice and this permission notice shall be included in 0017 // all copies or substantial portions of the Software. 0018 // 0019 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0020 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0021 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0022 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0023 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0024 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 0025 // THE SOFTWARE. 0026 0027 protocol StringGenerator{ 0028 func generateStringColor(color: Color?, backgroundColor: BackgroundColor?, styles: [Style]?, text: String) -> String 0029 } 0030 0031 struct ConsoleStringGenerator
StringGenerator.swift:31 struct ConsoleStringGenerator: StringGenerator {StringGenerator.swift:52 struct XcodeColorsStringGenerator: StringGenerator {: StringGenerator { 0032 func generateStringColor
Rainbow.swift:78 return ConsoleStringGenerator().generateStringColor(color, backgroundColor: backgroundColor, styles: styles, text: text)(color: Color?, backgroundColor: BackgroundColor?, styles: [Style]?, text: String) -> String { 0033 var codes: [UInt8] = [] 0034 if let color = color { 0035 codes.append(color.value) 0036 } 0037 if let backgroundColor = backgroundColor { 0038 codes.append(backgroundColor.value) 0039 } 0040 if let styles = styles { 0041 codes += styles.map{$0.value} 0042 } 0043 0044 if codes.isEmpty { 0045 return text 0046 } else { 0047 return "\(ControlCode.CSI)\(codes.map{String($0)}.joinWithSeparator(";"))m\(text)\(ControlCode.CSI)0m" 0048 } 0049 } 0050 } 0051 0052 struct XcodeColorsStringGenerator
Rainbow.swift:78 return ConsoleStringGenerator().generateStringColor(color, backgroundColor: backgroundColor, styles: styles, text: text): StringGenerator { 0053 func generateStringColor
Rainbow.swift:76 return XcodeColorsStringGenerator().generateStringColor(color, backgroundColor: backgroundColor, styles: styles, text: text)(color: Color?, backgroundColor: BackgroundColor?, styles: [Style]?, text: String) -> String { 0054 0055 var result = "" 0056 var added = false 0057 0058 if let color = color where color != .Default { 0059 result += "\(ControlCode.CSI)\(color.xcodeColorsDescription);" 0060 added = true 0061 } 0062 0063 if let backgroundColor = backgroundColor where backgroundColor != .Default { 0064 result += "\(ControlCode.CSI)\(backgroundColor.xcodeColorsDescription);" 0065 added = true 0066 } 0067 0068 result += text 0069 0070 if added { 0071 result += "\(ControlCode.CSI);" 0072 } 0073 0074 return result 0075 } 0076 }
Rainbow.swift:76 return XcodeColorsStringGenerator().generateStringColor(color, backgroundColor: backgroundColor, styles: styles, text: text)