Files
ghostty/macos/Sources/Helpers/Extensions/NSAppearance+Extension.swift
Lukas daab08ec01 macOS: drop the cross-platform check and abstraction
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-12 14:00:03 +02:00

32 lines
825 B
Swift

import AppKit
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 = NSColor(config.backgroundColor)
if color.isLightColor {
self.init(named: .aqua)
} else {
self.init(named: .darkAqua)
}
default:
return nil
}
}
}