@@ -2,7 +2,7 @@ import AppKit
22
33// MARK: - Highlighter
44
5- @ MainActor public enum CodeBlockHighlighter {
5+ public enum CodeBlockHighlighter : Sendable {
66 private static let wordRx : NSRegularExpression ? = try ? NSRegularExpression ( pattern: #"\b(?:[a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9][a-zA-Z0-9_]*)\b"# )
77 private static let funcRx : NSRegularExpression ? = try ? NSRegularExpression ( pattern: #"\b([a-zA-Z_][a-zA-Z0-9_]*)\s*(?=\()"# )
88 private static let propRx : NSRegularExpression ? = try ? NSRegularExpression ( pattern: #"\.([a-zA-Z_][a-zA-Z0-9_]*)"# )
@@ -516,42 +516,42 @@ import AppKit
516516
517517 // Terminal output theme colors
518518 private static var termDir : NSColor {
519- NSApp . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
519+ CodeBlockTheme . isDark
520520 ? NSColor ( red: 0.35 , green: 0.7 , blue: 1.0 , alpha: 1 ) // bright blue
521521 : NSColor ( red: 0.0 , green: 0.3 , blue: 0.8 , alpha: 1 )
522522 }
523523 private static var termExec : NSColor {
524- NSApp . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
524+ CodeBlockTheme . isDark
525525 ? NSColor ( red: 0.4 , green: 0.9 , blue: 0.4 , alpha: 1 ) // green
526526 : NSColor ( red: 0.0 , green: 0.5 , blue: 0.0 , alpha: 1 )
527527 }
528528 private static var termSymlink : NSColor {
529- NSApp . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
529+ CodeBlockTheme . isDark
530530 ? NSColor ( red: 0.9 , green: 0.5 , blue: 0.9 , alpha: 1 ) // magenta
531531 : NSColor ( red: 0.6 , green: 0.0 , blue: 0.6 , alpha: 1 )
532532 }
533533 private static var termSize : NSColor {
534- NSApp . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
534+ CodeBlockTheme . isDark
535535 ? NSColor ( red: 0.85 , green: 0.85 , blue: 0.5 , alpha: 1 ) // yellow
536536 : NSColor ( red: 0.5 , green: 0.4 , blue: 0.0 , alpha: 1 )
537537 }
538538 private static var termDate : NSColor {
539- NSApp . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
539+ CodeBlockTheme . isDark
540540 ? NSColor ( red: 0.6 , green: 0.6 , blue: 0.7 , alpha: 1 ) // dim
541541 : NSColor ( red: 0.4 , green: 0.4 , blue: 0.5 , alpha: 1 )
542542 }
543543 private static var termPerm : NSColor {
544- NSApp . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
544+ CodeBlockTheme . isDark
545545 ? NSColor ( red: 0.6 , green: 0.7 , blue: 0.6 , alpha: 1 ) // muted green
546546 : NSColor ( red: 0.3 , green: 0.4 , blue: 0.3 , alpha: 1 )
547547 }
548548 private static var termPath : NSColor {
549- NSApp . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
549+ CodeBlockTheme . isDark
550550 ? NSColor ( red: 0.4 , green: 0.85 , blue: 0.85 , alpha: 1 ) // cyan
551551 : NSColor ( red: 0.0 , green: 0.5 , blue: 0.5 , alpha: 1 )
552552 }
553553 private static var termError : NSColor {
554- NSApp . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
554+ CodeBlockTheme . isDark
555555 ? NSColor ( red: 1.0 , green: 0.4 , blue: 0.4 , alpha: 1 ) // red
556556 : NSColor ( red: 0.8 , green: 0.0 , blue: 0.0 , alpha: 1 )
557557 }
@@ -565,7 +565,7 @@ import AppKit
565565 private static let termErrorRx : NSRegularExpression ? = try ? NSRegularExpression ( pattern: #"\b(?:error|Error|ERROR|fatal|FATAL|failed|FAILED|No such file|Permission denied|not found|cannot)\b"# )
566566 private static let termWarningRx : NSRegularExpression ? = try ? NSRegularExpression ( pattern: #"\b(?:warning|Warning|WARNING|deprecated|DEPRECATED|caution)\b"# )
567567 private static var termWarning : NSColor {
568- NSApp . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
568+ CodeBlockTheme . isDark
569569 ? NSColor ( red: 1.0 , green: 0.8 , blue: 0.2 , alpha: 1 ) // yellow
570570 : NSColor ( red: 0.7 , green: 0.5 , blue: 0.0 , alpha: 1 )
571571 }
@@ -655,7 +655,7 @@ import AppKit
655655
656656 /// Highlight a D1F diff line: background stripe for the diff marker, code syntax for the text.
657657 private static func highlightD1FLine( line: String , font: NSFont ) -> NSAttributedString {
658- let isDark = NSApp . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
658+ let isDark = CodeBlockTheme . isDark
659659 let trimmed = line. trimmingCharacters ( in: . whitespaces)
660660
661661 // Strip emoji prefix to get the code content for syntax highlighting
0 commit comments