1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +03:00

Console attributes.

This commit is contained in:
Rob Rix 2015-11-02 18:02:37 -05:00
parent 75703e1561
commit a22491ceda

View File

@ -24,6 +24,34 @@ private var isTTY = isatty(STDOUT_FILENO) != 0
private var isDumb = String.fromCString(getenv("TERM")).map { !$0.hasPrefix("dumb") } ?? false private var isDumb = String.fromCString(getenv("TERM")).map { !$0.hasPrefix("dumb") } ?? false
private var shouldFormat = isTTY && !isDumb private var shouldFormat = isTTY && !isDumb
private struct Attribute {
let colour: Colour
let style: Style
enum Colour: Int {
case Black = 30
case Red
case Green
case Yellow
case Blue
case Purple
case Cyan
case White
}
enum Style: Int {
case Normal = 0
case Bold = 1
case Underline = 4
}
func wrap(string: String) -> String {
return shouldFormat
? "\u{001B}[\(style);\(colour)m\(string)\u{001B}[0m"
: string
}
}
private func unified(patch: Patch<Term>, before: String, after: String) -> String { private func unified(patch: Patch<Term>, before: String, after: String) -> String {
return (patch.state.before.map { "{-\(unified($0, source: before))-}" } ?? "") return (patch.state.before.map { "{-\(unified($0, source: before))-}" } ?? "")
+ (patch.state.after.map { "{+\(unified($0, source: after))+}" } ?? "") + (patch.state.after.map { "{+\(unified($0, source: after))+}" } ?? "")