]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Syntax highlighter color updates
authorEric Kuck <eric@bluelinelabs.com>
Tue, 8 Jan 2019 10:35:06 +0000 (12:35 +0200)
committerRoopesh Chander <roop@roopc.net>
Mon, 14 Jan 2019 09:22:34 +0000 (14:52 +0530)
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
WireGuard/WireGuard/UI/macOS/View/ConfTextStorage.swift
WireGuard/WireGuard/UI/macOS/View/ConfTextView.swift

index 2db3d8749222cf5eaafcf784406b375d1db4f047..63c9cbf18009dc47f6aad957ba012f79b3edbd43 100644 (file)
@@ -3,22 +3,24 @@
 
 import Cocoa
 
+private let fontSize: CGFloat = 15
+
 class ConfTextStorage: NSTextStorage {
 
     struct TextColorTheme {
-        let black: NSColor
-        let red: NSColor
-        let green: NSColor
-        let yellow: NSColor
-        let blue: NSColor
-        let magenta: NSColor
-        let cyan: NSColor
-        let white: NSColor
-        let `default`: NSColor
+        let plainText: NSColor
+        let sections: NSColor
+        let key: NSColor
+        let url: NSColor
+        let urlAttribute: NSColor
+        let comments: NSColor
+        let number: NSColor
+        let error: NSColor
     }
 
-    let defaultFont = NSFont.systemFont(ofSize: 16)
-    private let boldFont = NSFont.boldSystemFont(ofSize: 16)
+    let defaultFont = NSFontManager.shared.convertWeight(true, of: NSFont.systemFont(ofSize: fontSize))
+    private let boldFont = NSFont.boldSystemFont(ofSize: fontSize)
+    private lazy var italicFont = NSFontManager.shared.convert(defaultFont, toHaveTrait: .italicFontMask)
 
     private var defaultAttributes: [NSAttributedString.Key: Any]! //swiftlint:disable:this implicitly_unwrapped_optional
     private var highlightAttributes: [UInt32: [NSAttributedString.Key: Any]]! //swiftlint:disable:this implicitly_unwrapped_optional
@@ -39,76 +41,59 @@ class ConfTextStorage: NSTextStorage {
         fatalError("init(pasteboardPropertyList:ofType:) has not been implemented")
     }
 
-    //swiftlint:disable:next function_body_length
     func updateAttributes(for theme: TextColorTheme) {
         self.defaultAttributes = [
-            .foregroundColor: theme.default,
+            .foregroundColor: theme.plainText,
             .font: defaultFont
         ]
 
         self.highlightAttributes = [
             HighlightSection.rawValue: [
-                .foregroundColor: theme.black,
+                .foregroundColor: theme.sections,
                 .font: boldFont
             ],
             HighlightKeytype.rawValue: [
-                .foregroundColor: theme.blue,
+                .foregroundColor: theme.key,
                 .font: boldFont
             ],
             HighlightKey.rawValue: [
-                .foregroundColor: theme.yellow,
-                .font: boldFont
-            ],
-            HighlightCmd.rawValue: [
-                .foregroundColor: theme.white,
+                .foregroundColor: theme.plainText,
                 .font: defaultFont
             ],
             HighlightIP.rawValue: [
-                .foregroundColor: theme.green,
+                .foregroundColor: theme.url,
                 .font: defaultFont
             ],
             HighlightCidr.rawValue: [
-                .foregroundColor: theme.yellow,
+                .foregroundColor: theme.urlAttribute,
                 .font: defaultFont
             ],
             HighlightHost.rawValue: [
-                .foregroundColor: theme.green,
-                .font: boldFont
-            ],
-            HighlightPort.rawValue: [
-                .foregroundColor: theme.magenta,
+                .foregroundColor: theme.url,
                 .font: defaultFont
             ],
-            HighlightTable.rawValue: [
-                .foregroundColor: theme.blue,
-                .font: defaultFont
-            ],
-            HighlightFwMark.rawValue: [
-                .foregroundColor: theme.blue,
+            HighlightPort.rawValue: [
+                .foregroundColor: theme.urlAttribute,
                 .font: defaultFont
             ],
             HighlightMTU.rawValue: [
-                .foregroundColor: theme.blue,
-                .font: defaultFont
-            ],
-            HighlightSaveConfig.rawValue: [
-                .foregroundColor: theme.blue,
+                .foregroundColor: theme.number,
                 .font: defaultFont
             ],
             HighlightKeepalive.rawValue: [
-                .foregroundColor: theme.blue,
+                .foregroundColor: theme.number,
                 .font: defaultFont
             ],
             HighlightComment.rawValue: [
-                .foregroundColor: theme.cyan,
-                .font: defaultFont
+                .foregroundColor: theme.comments,
+                .font: italicFont
             ],
             HighlightDelimiter.rawValue: [
-                .foregroundColor: theme.cyan,
+                .foregroundColor: theme.plainText,
                 .font: defaultFont
             ],
             HighlightError.rawValue: [
-                .foregroundColor: theme.red,
+                .foregroundColor: theme.error,
                 .font: defaultFont,
                 .underlineStyle: 1
             ]
index 8526e6c01e1cc72daa65cf1097866e46e04c1553..cd91b01e666e2b9f5b8016ee2793db2fc82d273e 100644 (file)
@@ -38,9 +38,9 @@ class ConfTextView: NSTextView {
         let theme: ConfTextStorage.TextColorTheme
         switch effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]) ?? .aqua {
         case .darkAqua:
-            theme = ConfTextStorage.TextColorTheme(black: NSColor(hex: "#c7c7c7"), red: NSColor(hex: "#dc322f"), green: NSColor(hex: "#859900"), yellow: NSColor(hex: "#c7c400"), blue: NSColor(hex: "#268bd2"), magenta: NSColor(hex: "#d33682"), cyan: NSColor(hex: "#2aa198"), white: NSColor(hex: "#383838"), default: NSColor(hex: "#c7c7c7"))
+            theme = ConfTextStorage.TextColorTheme(plainText: NSColor(hex: "#FFFFFF"), sections: NSColor(hex: "#91D462"), key: NSColor(hex: "#FC5FA3"), url: NSColor(hex: "#53A5FB"), urlAttribute: NSColor(hex: "#75B492"), comments: NSColor(hex: "#6C7986"), number: NSColor(hex: "#9686F5"), error: NSColor(hex: "#FC6A5D"))
         default:
-            theme = ConfTextStorage.TextColorTheme(black: NSColor(hex: "#000000"), red: NSColor(hex: "#c91b00"), green: NSColor(hex: "#00c200"), yellow: NSColor(hex: "#c7c400"), blue: NSColor(hex: "#0225c7"), magenta: NSColor(hex: "#c930c7"), cyan: NSColor(hex: "#00c5c7"), white: NSColor(hex: "#c7c7c7"), default: NSColor(hex: "#000000"))
+            theme = ConfTextStorage.TextColorTheme(plainText: NSColor(hex: "#000000"), sections: NSColor(hex: "#326D74"), key: NSColor(hex: "#9B2393"), url: NSColor(hex: "#0E0EFF"), urlAttribute: NSColor(hex: "#815F03"), comments: NSColor(hex: "#536579"), number: NSColor(hex: "#1C00CF"), error: NSColor(hex: "#C41A16"))
         }
         confTextStorage.updateAttributes(for: theme)
     }