Skip to content

Commit 6899b3a

Browse files
committed
feat: support mac os
1 parent 067d0d3 commit 6899b3a

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import PackageDescription
66
let package = Package(
77
name: "gitdiff",
88
platforms: [
9-
.iOS(.v15)
9+
.iOS(.v15),
10+
.macOS(.v13)
1011
],
1112
products: [
1213
.library(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import SwiftUI
2+
3+
#if os(iOS) || os(tvOS) || os(watchOS)
4+
import UIKit
5+
#endif
6+
#if os(macOS)
7+
import AppKit
8+
#endif
9+
10+
/// Cross-platform system background color wrapper
11+
enum PlatformColors {
12+
static var background: Color {
13+
#if os(iOS) || os(tvOS) || os(watchOS)
14+
return Color(UIColor.systemBackground)
15+
#elseif os(macOS)
16+
if #available(macOS 10.15, *) {
17+
// There is no NSColor.systemBackground; windowBackgroundColor is closest for content areas
18+
return Color(NSColor.windowBackgroundColor)
19+
} else {
20+
return Color.white
21+
}
22+
#else
23+
return Color.white
24+
#endif
25+
}
26+
}
27+
28+
extension Color {
29+
/// A cross-platform background color similar to system background.
30+
public static var appBackground: Color { PlatformColors.background }
31+
}

Sources/gitdiff/Views/DiffFileView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ struct DiffFileView: View {
110110

111111
DiffFileView(file: sampleFile)
112112
.padding()
113-
.background(Color(.systemBackground))
113+
.background(Color.appBackground)
114114
}

Sources/gitdiff/Views/DiffLineView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,5 @@ struct DiffLineView: View {
142142
)
143143
)
144144
}
145-
.background(Color(.systemBackground))
145+
.background(Color.appBackground)
146146
}

Sources/gitdiff/Views/DiffRenderer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public struct DiffRenderer: View {
6060
.padding()
6161
}
6262
}
63-
.background(Color(.systemBackground))
63+
.background(Color.appBackground)
6464
}
6565
}
6666

@@ -103,7 +103,7 @@ public struct DiffRenderer: View {
103103

104104
// With dark theme
105105
DiffRenderer(diffText: text)
106-
.diffTheme(.vsCodeDark)
106+
.diffTheme(.dark)
107107

108108
// With custom configuration
109109
DiffRenderer(diffText: text)

0 commit comments

Comments
 (0)