macOS: Make color theme use a dict

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander
2019-01-22 01:58:58 +05:30
parent 1bc2177883
commit e0798b8a97
2 changed files with 34 additions and 55 deletions
@@ -5,64 +5,43 @@ import Cocoa
protocol ConfTextColorTheme { protocol ConfTextColorTheme {
var defaultColor: NSColor { get } var defaultColor: NSColor { get }
var colorMap: [UInt32: NSColor] { get }
func color(for: highlight_type) -> NSColor
} }
struct ConfTextAquaColorTheme: ConfTextColorTheme { struct ConfTextAquaColorTheme: ConfTextColorTheme {
var defaultColor: NSColor { var defaultColor = NSColor(hex: "#000000")
return NSColor(hex: "#000000") // Plain text in Xcode var colorMap: [UInt32: NSColor] = [
} HighlightSection.rawValue: NSColor(hex: "#326D74"), // Class name in Xcode
HighlightField.rawValue: NSColor(hex: "#9B2393"), // Keywords in Xcode
func color(for highlightType: highlight_type) -> NSColor { HighlightPublicKey.rawValue: NSColor(hex: "#643820"), // Preprocessor directives in Xcode
switch highlightType.rawValue { HighlightPrivateKey.rawValue: NSColor(hex: "#643820"), // Preprocessor directives in Xcode
case HighlightSection.rawValue: HighlightPresharedKey.rawValue: NSColor(hex: "#643820"), // Preprocessor directives in Xcode
return NSColor(hex: "#326D74") // Class name in Xcode HighlightIP.rawValue: NSColor(hex: "#0E0EFF"), // URLs in Xcode
case HighlightField.rawValue: HighlightHost.rawValue: NSColor(hex: "#0E0EFF"), // URLs in Xcode
return NSColor(hex: "#9B2393") // Keywords in Xcode HighlightCidr.rawValue: NSColor(hex: "#815F03"), // Attributes in Xcode
case HighlightPublicKey.rawValue, HighlightPrivateKey.rawValue, HighlightPresharedKey.rawValue: HighlightPort.rawValue: NSColor(hex: "#815F03"), // Attributes in Xcode
return NSColor(hex: "#643820") // Preprocessor directives in Xcode HighlightMTU.rawValue: NSColor(hex: "#1C00CF"), // Numbers in Xcode
case HighlightIP.rawValue, HighlightHost.rawValue: HighlightKeepalive.rawValue: NSColor(hex: "#1C00CF"), // Numbers in Xcode
return NSColor(hex: "#0E0EFF") // URLs in Xcode HighlightComment.rawValue: NSColor(hex: "#536579"), // Comments in Xcode
case HighlightCidr.rawValue, HighlightPort.rawValue: HighlightError.rawValue: NSColor(hex: "#C41A16") // Strings in Xcode
return NSColor(hex: "#815F03") // Attributes in Xcode ]
case HighlightMTU.rawValue, HighlightKeepalive.rawValue:
return NSColor(hex: "#1C00CF") // Numbers in Xcode
case HighlightComment.rawValue:
return NSColor(hex: "#536579") // Comments in Xcode
case HighlightError.rawValue:
return NSColor(hex: "#C41A16") // Strings in Xcode
default:
return defaultColor
}
}
} }
struct ConfTextDarkAquaColorTheme: ConfTextColorTheme { struct ConfTextDarkAquaColorTheme: ConfTextColorTheme {
var defaultColor: NSColor { var defaultColor = NSColor(hex: "#FFFFFF") // Plain text in Xcode
return NSColor(hex: "#FFFFFF") // Plain text in Xcode var colorMap: [UInt32: NSColor] = [
} HighlightSection.rawValue: NSColor(hex: "#91D462"), // Class name in Xcode
HighlightField.rawValue: NSColor(hex: "#FC5FA3"), // Keywords in Xcode
func color(for highlightType: highlight_type) -> NSColor { HighlightPublicKey.rawValue: NSColor(hex: "#FD8F3F"), // Preprocessor directives in Xcode
switch highlightType.rawValue { HighlightPrivateKey.rawValue: NSColor(hex: "#FD8F3F"), // Preprocessor directives in Xcode
case HighlightSection.rawValue: HighlightPresharedKey.rawValue: NSColor(hex: "#FD8F3F"), // Preprocessor directives in Xcode
return NSColor(hex: "#91D462") // Class name in Xcode HighlightIP.rawValue: NSColor(hex: "#53A5FB"), // URLs in Xcode
case HighlightField.rawValue: HighlightHost.rawValue: NSColor(hex: "#53A5FB"), // URLs in Xcode
return NSColor(hex: "#FC5FA3") // Keywords in Xcode HighlightCidr.rawValue: NSColor(hex: "#75B492"), // Attributes in Xcode
case HighlightPublicKey.rawValue, HighlightPrivateKey.rawValue, HighlightPresharedKey.rawValue: HighlightPort.rawValue: NSColor(hex: "#75B492"), // Attributes in Xcode
return NSColor(hex: "#FD8F3F") // Preprocessor directives in Xcode HighlightMTU.rawValue: NSColor(hex: "#9686F5"), // Numbers in Xcode
case HighlightIP.rawValue, HighlightHost.rawValue: HighlightKeepalive.rawValue: NSColor(hex: "#9686F5"), // Numbers in Xcode
return NSColor(hex: "#53A5FB") // URLs in Xcode HighlightComment.rawValue: NSColor(hex: "#6C7986"), // Comments in Xcode
case HighlightCidr.rawValue, HighlightPort.rawValue: HighlightError.rawValue: NSColor(hex: "#FF4C4C") // Strings in Xcode
return NSColor(hex: "#75B492") // Attributes in Xcode ]
case HighlightMTU.rawValue, HighlightKeepalive.rawValue:
return NSColor(hex: "#9686F5") // Numbers in Xcode
case HighlightComment.rawValue:
return NSColor(hex: "#6C7986") // Comments in Xcode
case HighlightError.rawValue:
return NSColor(hex: "#FF4C4C") // Strings in Xcode
default:
return defaultColor
}
}
} }
@@ -103,7 +103,7 @@ class ConfTextStorage: NSTextStorage {
let range = NSRange(location: span.start, length: span.len) let range = NSRange(location: span.start, length: span.len)
backingStore.setAttributes(nonColorAttributes(for: span.type), range: range) backingStore.setAttributes(nonColorAttributes(for: span.type), range: range)
if let textColorTheme = textColorTheme { if let textColorTheme = textColorTheme {
let color = textColorTheme.color(for: span.type) let color = textColorTheme.colorMap[span.type.rawValue] ?? textColorTheme.defaultColor
backingStore.addAttribute(.foregroundColor, value: color, range: range) backingStore.addAttribute(.foregroundColor, value: color, range: range)
} }