0001 // 0002 // OutputTarget.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 #if os(Linux) 0028 import Glibc 0029 #else 0030 import Darwin.C 0031 #endif 0032 0033 private func getEnvValue(key: String) -> String? { 0034 let value = getenv(key) 0035 return value != nil ? String.fromCString(value) : nil 0036 } 0037 0038 0039 /// 0040 /** 0041 Output target of Rainbow. 0042 0043 - Unknown: Unknown target. 0044 - Console: A valid console is detected connected. 0045 - XcodeColors: Used in Xcode with XcodeColors enabled. 0046 */ 0047 public enum OutputTarget
OutputTarget.swift:55 let xcodeColorsEnabled = (getEnvValue("XcodeColors") == "YES")OutputTarget.swift:61 let termType = getEnvValue("TERM"){ 0048 case Unknown
OutputTarget.swift:53 static var currentOutputTarget: OutputTarget = {Rainbow.swift:44 public static var outputTarget = OutputTarget.currentOutputTarget0049 case Console
OutputTarget.swift:66 return .UnknownRainbow.swift:79 case .Unknown:0050 case XcodeColors
OutputTarget.swift:63 return .ConsoleRainbow.swift:77 case .Console:0051 0052 /// Detected output target by current envrionment. 0053 static var currentOutputTarget
OutputTarget.swift:57 return .XcodeColorsRainbow.swift:75 case .XcodeColors:: OutputTarget = { 0054 // Check if Xcode Colors is installed and enabled. 0055 let xcodeColorsEnabled = (getEnvValue("XcodeColors") == "YES") 0056 if xcodeColorsEnabled { 0057 return .XcodeColors 0058 } 0059 0060 // Check if we are in any term env and the output is a tty. 0061 let termType = getEnvValue("TERM") 0062 if let t = termType where t.lowercaseString != "dumb" && isatty(fileno(stdout)) != 0 { 0063 return .Console 0064 } 0065 0066 return .Unknown 0067 }() 0068 } 0069
Rainbow.swift:44 public static var outputTarget = OutputTarget.currentOutputTarget