import UIKit import Runestone final class PadXcodeTheme: Theme { var backgroundColor: UIColor { UIColor(hex: "#1E1E1E") } var userInterfaceStyle: UIUserInterfaceStyle { .dark } var font: UIFont { UIFont.monospacedSystemFont(ofSize: 14, weight: .regular) } var textColor: UIColor { UIColor(hex: "#D4D4D4") } var gutterBackgroundColor: UIColor { UIColor(hex: "#252526") } var gutterHairlineColor: UIColor { UIColor(hex: "#3C3C3C") } var lineNumberColor: UIColor { UIColor(hex: "#6E7681") } var lineNumberFont: UIFont { UIFont.monospacedSystemFont(ofSize: 12, weight: .regular) } var selectedLineBackgroundColor: UIColor { UIColor(hex: "#2A2D2E") } var selectedLinesLineNumberColor: UIColor { UIColor(hex: "#C8C8C8") } var selectedLinesGutterBackgroundColor: UIColor { UIColor(hex: "#2A2D2E") } var markedTextBackgroundColor: UIColor { UIColor(hex: "#264F78").withAlphaComponent(0.4) } var markedTextBackgroundCornerRadius: CGFloat { 2 } var invisibleCharactersColor: UIColor { UIColor(hex: "#404040") } var pageGuideHairlineColor: UIColor { UIColor(hex: "#404040") } var pageGuideBackgroundColor: UIColor { UIColor(hex: "#1A1A1A") } func textStyle(for highlightName: String) -> TextStyle? { switch highlightName { case "keyword", "keyword.control", "keyword.operator", "keyword.other", "keyword.declaration", "storage.type": return TextStyle(color: UIColor(hex: "#FF7AB2"), bold: true) case "storage.modifier": return TextStyle(color: UIColor(hex: "#FF7AB2")) case "type", "type.builtin", "entity.name.type", "entity.name.type.class", "entity.name.type.struct", "entity.name.type.enum", "entity.name.type.protocol": return TextStyle(color: UIColor(hex: "#DABAFF")) case "type.parameter": return TextStyle(color: UIColor(hex: "#6BDFFF")) case "function", "entity.name.function", "meta.function-call", "function.method": return TextStyle(color: UIColor(hex: "#67B7FB")) case "function.builtin": return TextStyle(color: UIColor(hex: "#67B7FB"), bold: true) case "variable", "variable.other", "variable.other.member": return TextStyle(color: UIColor(hex: "#D4D4D4")) case "variable.builtin": return TextStyle(color: UIColor(hex: "#FF7AB2")) case "property", "variable.other.property": return TextStyle(color: UIColor(hex: "#72B9D5")) case "constant", "constant.builtin": return TextStyle(color: UIColor(hex: "#D9C97C"), bold: true) case "constant.numeric", "number": return TextStyle(color: UIColor(hex: "#D9C97C")) case "string", "string.special": return TextStyle(color: UIColor(hex: "#FF8170")) case "string.escape": return TextStyle(color: UIColor(hex: "#FF8170"), bold: true) case "comment", "comment.line", "comment.block": return TextStyle(color: UIColor(hex: "#7F8C98"), italic: true) case "comment.block.documentation": return TextStyle(color: UIColor(hex: "#6A9955"), italic: true) case "operator", "punctuation.operator", "punctuation.bracket", "punctuation.delimiter": return TextStyle(color: UIColor(hex: "#D4D4D4")) case "attribute": return TextStyle(color: UIColor(hex: "#BF86C8")) default: return nil } } } final class PadXcodeLightTheme: Theme { var backgroundColor: UIColor { UIColor(hex: "#FFFFFF") } var userInterfaceStyle: UIUserInterfaceStyle { .light } var font: UIFont { UIFont.monospacedSystemFont(ofSize: 14, weight: .regular) } var textColor: UIColor { UIColor(hex: "#000000") } var gutterBackgroundColor: UIColor { UIColor(hex: "#F2F2F2") } var gutterHairlineColor: UIColor { UIColor(hex: "#D8D8D8") } var lineNumberColor: UIColor { UIColor(hex: "#A0A0A0") } var lineNumberFont: UIFont { UIFont.monospacedSystemFont(ofSize: 12, weight: .regular) } var selectedLineBackgroundColor: UIColor { UIColor(hex: "#ECF5FF") } var selectedLinesLineNumberColor: UIColor { UIColor(hex: "#3A3A3A") } var selectedLinesGutterBackgroundColor: UIColor { UIColor(hex: "#E8F0FA") } var markedTextBackgroundColor: UIColor { UIColor(hex: "#B5D0F7").withAlphaComponent(0.4) } var markedTextBackgroundCornerRadius: CGFloat { 2 } var invisibleCharactersColor: UIColor { UIColor(hex: "#CCCCCC") } var pageGuideHairlineColor: UIColor { UIColor(hex: "#DDDDDD") } var pageGuideBackgroundColor: UIColor { UIColor(hex: "#F9F9F9") } func textStyle(for highlightName: String) -> TextStyle? { switch highlightName { case "keyword", "keyword.control", "keyword.operator", "keyword.other", "keyword.declaration", "storage.type": return TextStyle(color: UIColor(hex: "#AD3DA4"), bold: true) case "storage.modifier": return TextStyle(color: UIColor(hex: "#AD3DA4")) case "type", "type.builtin", "entity.name.type", "entity.name.type.class", "entity.name.type.struct", "entity.name.type.enum", "entity.name.type.protocol": return TextStyle(color: UIColor(hex: "#703DAA")) case "type.parameter": return TextStyle(color: UIColor(hex: "#047CB0")) case "function", "entity.name.function", "meta.function-call", "function.method": return TextStyle(color: UIColor(hex: "#3900A0")) case "function.builtin": return TextStyle(color: UIColor(hex: "#3900A0"), bold: true) case "variable", "variable.other", "variable.other.member": return TextStyle(color: UIColor(hex: "#000000")) case "variable.builtin": return TextStyle(color: UIColor(hex: "#AD3DA4")) case "property", "variable.other.property": return TextStyle(color: UIColor(hex: "#047CB0")) case "constant", "constant.builtin": return TextStyle(color: UIColor(hex: "#272AD8"), bold: true) case "constant.numeric", "number": return TextStyle(color: UIColor(hex: "#272AD8")) case "string", "string.special": return TextStyle(color: UIColor(hex: "#C41A16")) case "string.escape": return TextStyle(color: UIColor(hex: "#C41A16"), bold: true) case "comment", "comment.line", "comment.block": return TextStyle(color: UIColor(hex: "#5D6C79"), italic: true) case "comment.block.documentation": return TextStyle(color: UIColor(hex: "#265B31"), italic: true) case "operator", "punctuation.operator", "punctuation.bracket", "punctuation.delimiter": return TextStyle(color: UIColor(hex: "#000000")) case "attribute": return TextStyle(color: UIColor(hex: "#6C36A9")) default: return nil } } } // MARK: - TextStyle helpers extension TextStyle { init(color: UIColor, bold: Bool = false, italic: Bool = false) { self.init() self.color = color if bold { self.fontTraits.insert(.traitBold) } if italic { self.fontTraits.insert(.traitItalic) } } } // MARK: - UIColor hex extension UIColor { convenience init(hex: String) { var h = hex.trimmingCharacters(in: .whitespacesAndNewlines) h = h.hasPrefix("#") ? String(h.dropFirst()) : h var rgb: UInt64 = 0 Scanner(string: h).scanHexInt64(&rgb) self.init(red: CGFloat((rgb >> 16) & 0xFF) / 255, green: CGFloat((rgb >> 8) & 0xFF) / 255, blue: CGFloat( rgb & 0xFF) / 255, alpha: 1) } }