<commit_before>//
//  Formatting.swift
//  Carthage
//
//  Created by <NAME> on 1/29/15.
//  Copyright (c) 2015 Carthage. All rights reserved.
//

import Commandant
import Foundation
import LlamaKit
import PrettyColors

/// Wraps a string with terminal colors and formatting or passes it through, depending on `colorful`.
private func wrap(colorful: Bool)(wrap: Color.Wrap)(string: String) -> String {
	return colorful ? wrap.wrap(string) : string
}

/// Information about the possible parent terminal.
internal struct Terminal {
	/// Terminal type retrieved from `TERM` environment variable.
	static var terminalType: String? {
		return getEnvironmentVariable("TERM").value()
	}
	
	/// Whether terminal type is `dumb`.
	static var isDumb: Bool {
		return terminalType?.caseInsensitiveCompare("dumb") == NSComparisonResult.OrderedSame ?? false
	}
	
	/// Whether STDOUT is a TTY.
	static var isTTY: Bool {
		return isatty(STDOUT_FILENO) == 1
	}
}

public enum ColorArgument: String, ArgumentType, Printable {
	case Auto = "auto"
	case Never = "never"
	case Always = "always"
	
	/// Whether to color and format.
	public var isColorful: Bool {
		switch self {
		case .Always:
			return true
		case .Never:
			return false
		case .Auto:
			return Terminal.isTTY && !Terminal.isDumb
		}
	}
	
	public var description: String {
		return self.rawValue
	}
	
	public static let name = "color"
	
	public static func fromString(string: String) -> ColorArgument? {
		return self(rawValue: string.lowercaseString)
	}
	
}

public struct ColorOptions: OptionsType {
	let argument: ColorArgument
	let formatting: Formatting
	
	struct Formatting {
		let colorful: Bool
		
		/// Wraps a string with terminal colors and formatting or passes it through.
		typealias Wrap = (string: String) -> String
		
		init(_ colorful: Bool) {
			self.colorful    = colorful
			self.bulletin    = wrap(colorful)(wrap: Color.Wrap(foreground: .Blue, style: .Bold))
			self.bullets     = self.bulletin(string: "***") + " "
			self.URL         = wrap(colorful)(wrap: Color.Wrap(styles: .Underlined))
			self.projectName = wrap(colorful)(wrap: Color.Wrap(styles: .Bold))
			self.path        = wrap(colorful)(wrap: Color.Wrap(foreground: .Yellow))
		}
		
		let bulletin: Wrap
		let bullets: String
		
		let URL: Wrap
		let projectName: Wrap
		let path: Wrap
		
		/// Wraps a string in quotation marks and formatting.
		func quote(string: String, quotationMark: String = "\"") -> String {
			return wrap(colorful)(wrap: Color.Wrap(foreground: .Green))(string: quotationMark + string + quotationMark)
		}
	}
	
	static func create(argument: ColorArgument) -> ColorOptions {
		return self(argument: argument, formatting: Formatting(argument.isColorful))
	}
	
	public static func evaluate(m: CommandMode) -> Result<ColorOptions> {
		return create
			<*> m <| Option(key: "color", defaultValue: ColorArgument.Auto, usage: "apply Terminal colors and formatting — ‘auto’ || ‘always’ || ‘never’")
	}
}
<commit_msg>Remove all unnecessary `self.` from Formatting initializer.<commit_after>//
//  Formatting.swift
//  Carthage
//
//  Created by <NAME> on 1/29/15.
//  Copyright (c) 2015 Carthage. All rights reserved.
//

import Commandant
import Foundation
import LlamaKit
import PrettyColors

/// Wraps a string with terminal colors and formatting or passes it through, depending on `colorful`.
private func wrap(colorful: Bool)(wrap: Color.Wrap)(string: String) -> String {
	return colorful ? wrap.wrap(string) : string
}

/// Information about the possible parent terminal.
internal struct Terminal {
	/// Terminal type retrieved from `TERM` environment variable.
	static var terminalType: String? {
		return getEnvironmentVariable("TERM").value()
	}
	
	/// Whether terminal type is `dumb`.
	static var isDumb: Bool {
		return terminalType?.caseInsensitiveCompare("dumb") == NSComparisonResult.OrderedSame ?? false
	}
	
	/// Whether STDOUT is a TTY.
	static var isTTY: Bool {
		return isatty(STDOUT_FILENO) == 1
	}
}

public enum ColorArgument: String, ArgumentType, Printable {
	case Auto = "auto"
	case Never = "never"
	case Always = "always"
	
	/// Whether to color and format.
	public var isColorful: Bool {
		switch self {
		case .Always:
			return true
		case .Never:
			return false
		case .Auto:
			return Terminal.isTTY && !Terminal.isDumb
		}
	}
	
	public var description: String {
		return self.rawValue
	}
	
	public static let name = "color"
	
	public static func fromString(string: String) -> ColorArgument? {
		return self(rawValue: string.lowercaseString)
	}
	
}

public struct ColorOptions: OptionsType {
	let argument: ColorArgument
	let formatting: Formatting
	
	struct Formatting {
		let colorful: Bool
		
		/// Wraps a string with terminal colors and formatting or passes it through.
		typealias Wrap = (string: String) -> String
		
		init(_ colorful: Bool) {
			self.colorful = colorful
			bulletin    = wrap(colorful)(wrap: Color.Wrap(foreground: .Blue, style: .Bold))
			bullets     = self.bulletin(string: "***") + " "
			URL         = wrap(colorful)(wrap: Color.Wrap(styles: .Underlined))
			projectName = wrap(colorful)(wrap: Color.Wrap(styles: .Bold))
			path        = wrap(colorful)(wrap: Color.Wrap(foreground: .Yellow))
		}
		
		let bulletin: Wrap
		let bullets: String
		
		let URL: Wrap
		let projectName: Wrap
		let path: Wrap
		
		/// Wraps a string in quotation marks and formatting.
		func quote(string: String, quotationMark: String = "\"") -> String {
			return wrap(colorful)(wrap: Color.Wrap(foreground: .Green))(string: quotationMark + string + quotationMark)
		}
	}
	
	static func create(argument: ColorArgument) -> ColorOptions {
		return self(argument: argument, formatting: Formatting(argument.isColorful))
	}
	
	public static func evaluate(m: CommandMode) -> Result<ColorOptions> {
		return create
			<*> m <| Option(key: "color", defaultValue: ColorArgument.Auto, usage: "apply Terminal colors and formatting — ‘auto’ || ‘always’ || ‘never’")
	}
}

{'fraction_non_alphanumeric': 0.11419441641439623, 'fraction_numerical': 0.003363605785401951, 'mean_word_length': 3.686367218282112, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2624481', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1776, 'n_words': 568}