68 lines
2.5 KiB
Swift
68 lines
2.5 KiB
Swift
import SwiftUI
|
|
import AppKit
|
|
import SwiftTerm
|
|
|
|
/// Offizielle Dracula-Palette (https://draculatheme.com/contribute).
|
|
enum Dracula {
|
|
static let background = SwiftUI.Color(hex: "282A36")
|
|
static let currentLine = SwiftUI.Color(hex: "44475A")
|
|
static let foreground = SwiftUI.Color(hex: "F8F8F2")
|
|
static let comment = SwiftUI.Color(hex: "6272A4")
|
|
static let cyan = SwiftUI.Color(hex: "8BE9FD")
|
|
static let green = SwiftUI.Color(hex: "50FA7B")
|
|
static let orange = SwiftUI.Color(hex: "FFB86C")
|
|
static let pink = SwiftUI.Color(hex: "FF79C6")
|
|
static let purple = SwiftUI.Color(hex: "BD93F9")
|
|
static let red = SwiftUI.Color(hex: "FF5555")
|
|
static let yellow = SwiftUI.Color(hex: "F1FA8C")
|
|
|
|
/// ANSI-Index 0-15 -> Dracula-Farbe.
|
|
static func color(for index: Int?) -> SwiftUI.Color {
|
|
guard let index else { return foreground }
|
|
switch index {
|
|
case 0: return SwiftUI.Color(hex: "21222C")
|
|
case 1: return red
|
|
case 2: return green
|
|
case 3: return yellow
|
|
case 4: return purple
|
|
case 5: return pink
|
|
case 6: return cyan
|
|
case 7: return foreground
|
|
case 8: return comment
|
|
case 9: return SwiftUI.Color(hex: "FF6E6E")
|
|
case 10: return SwiftUI.Color(hex: "69FF94")
|
|
case 11: return SwiftUI.Color(hex: "FFFFA5")
|
|
case 12: return SwiftUI.Color(hex: "D6ACFF")
|
|
case 13: return SwiftUI.Color(hex: "FF92DF")
|
|
case 14: return SwiftUI.Color(hex: "A4FFFF")
|
|
default: return SwiftUI.Color(hex: "FFFFFF")
|
|
}
|
|
}
|
|
|
|
static func nsColor(for index: Int?) -> NSColor {
|
|
NSColor(color(for: index))
|
|
}
|
|
|
|
static let nsBackground = NSColor(SwiftUI.Color(hex: "282A36"))
|
|
static let nsSelection = NSColor(SwiftUI.Color(hex: "44475A"))
|
|
|
|
/// 16 ANSI colors for the terminal emulator (SwiftTerm palette).
|
|
static var ansiPalette: [SwiftTerm.Color] {
|
|
["21222C", "FF5555", "50FA7B", "F1FA8C", "BD93F9", "FF79C6", "8BE9FD", "F8F8F2",
|
|
"6272A4", "FF6E6E", "69FF94", "FFFFA5", "D6ACFF", "FF92DF", "A4FFFF", "FFFFFF"]
|
|
.compactMap { SwiftTerm.Color.parse("#\($0)") }
|
|
}
|
|
}
|
|
|
|
extension SwiftUI.Color {
|
|
init(hex: String) {
|
|
let clean = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
|
|
var value: UInt64 = 0
|
|
Scanner(string: clean).scanHexInt64(&value)
|
|
let r = Double((value >> 16) & 0xFF) / 255
|
|
let g = Double((value >> 8) & 0xFF) / 255
|
|
let b = Double(value & 0xFF) / 255
|
|
self.init(red: r, green: g, blue: b)
|
|
}
|
|
}
|