summaryrefslogtreecommitdiff
path: root/macos/Sources/Helpers/Extensions/NSAppearance+Extension.swift
blob: 28edb1a35150d1819dfd6716286678bd36161565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Cocoa

extension NSAppearance {
    /// Returns true if the appearance is some kind of dark.
    var isDark: Bool {
        return name.rawValue.lowercased().contains("dark")
    }

    /// Initialize a desired NSAppearance for the Ghostty configuration.
    convenience init?(ghosttyConfig config: Ghostty.Config) {
        guard let theme = config.windowTheme else { return nil }
        switch (theme) {
        case "dark":
            self.init(named: .darkAqua)

        case "light":
            self.init(named: .aqua)

        case "auto":
            let color = OSColor(config.backgroundColor)
            if color.isLightColor {
                self.init(named: .aqua)
            } else {
                self.init(named: .darkAqua)
            }

        default:
            return nil
        }
    }
}