Skip to content

Commit daf1988

Browse files
remove uikit
1 parent 245900f commit daf1988

File tree

3 files changed

+75
-64
lines changed

3 files changed

+75
-64
lines changed

Sources/gitdiff/Views/DiffFileView.swift

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,27 @@
55
// Created by Tornike Gomareli on 18.06.25.
66
//
77

8-
98
import SwiftUI
109

1110
/// View for rendering a single file's diff
1211
struct DiffFileView: View {
1312
let file: DiffFile
14-
13+
1514
@Environment(\.diffConfiguration) private var configuration
16-
15+
1716
var body: some View {
1817
VStack(alignment: .leading, spacing: 0) {
1918
HStack {
2019
Image(systemName: "doc.text")
2120
.foregroundColor(configuration.theme.fileHeaderText)
22-
21+
2322
Text(file.displayName)
2423
.font(.system(.headline, design: configuration.fontFamily))
2524
.fontWeight(.bold)
2625
.foregroundColor(configuration.theme.fileHeaderText)
27-
26+
2827
Spacer()
29-
28+
3029
if file.isBinary {
3130
Text("Binary file")
3231
.font(.caption)
@@ -39,7 +38,7 @@ struct DiffFileView: View {
3938
}
4039
.padding()
4140
.background(configuration.theme.fileHeaderBackground)
42-
41+
4342
if file.isBinary {
4443
Text("Binary file not shown")
4544
.font(.system(size: configuration.fontSize, design: configuration.fontFamily))
@@ -55,7 +54,7 @@ struct DiffFileView: View {
5554
.padding(.vertical, 4)
5655
.frame(maxWidth: .infinity, alignment: .leading)
5756
.background(configuration.theme.headerBackground)
58-
57+
5958
VStack(spacing: configuration.lineSpacing.value) {
6059
ForEach(hunk.lines) { line in
6160
DiffLineView(line: line)
@@ -86,24 +85,30 @@ struct DiffFileView: View {
8685
lines: [
8786
DiffLine(type: .context, content: "import SwiftUI", oldLineNumber: 1, newLineNumber: 1),
8887
DiffLine(type: .context, content: "", oldLineNumber: 2, newLineNumber: 2),
89-
DiffLine(type: .context, content: "struct ContentView: View {", oldLineNumber: 3, newLineNumber: 3),
90-
DiffLine(type: .added, content: " let title = \"Hello World\"", oldLineNumber: nil, newLineNumber: 4),
91-
DiffLine(type: .context, content: " var body: some View {", oldLineNumber: 4, newLineNumber: 5),
92-
DiffLine(type: .removed, content: " Text(\"Hello, World!\")", oldLineNumber: 5, newLineNumber: nil),
88+
DiffLine(
89+
type: .context, content: "struct ContentView: View {", oldLineNumber: 3, newLineNumber: 3),
90+
DiffLine(
91+
type: .added, content: " let title = \"Hello World\"", oldLineNumber: nil,
92+
newLineNumber: 4),
93+
DiffLine(
94+
type: .context, content: " var body: some View {", oldLineNumber: 4, newLineNumber: 5),
95+
DiffLine(
96+
type: .removed, content: " Text(\"Hello, World!\")", oldLineNumber: 5,
97+
newLineNumber: nil),
9398
DiffLine(type: .added, content: " Text(title)", oldLineNumber: nil, newLineNumber: 6),
94-
DiffLine(type: .added, content: "}", oldLineNumber: nil, newLineNumber: 7)
99+
DiffLine(type: .added, content: "}", oldLineNumber: nil, newLineNumber: 7),
95100
]
96101
)
97-
102+
98103
let sampleFile = DiffFile(
99104
oldPath: "example.swift",
100105
newPath: "example.swift",
101106
hunks: [sampleHunk],
102107
isBinary: false,
103108
isRenamed: false
104109
)
105-
110+
106111
DiffFileView(file: sampleFile)
107112
.padding()
108-
.background(Color(UIColor.systemBackground))
113+
.background(Color(.systemBackground))
109114
}

Sources/gitdiff/Views/DiffLineView.swift

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
// Created by Tornike Gomareli on 18.06.25.
66
//
77

8-
98
import SwiftUI
109

1110
/// View for rendering a single diff line with GitHub-style formatting
1211
struct DiffLineView: View {
1312
let line: DiffLine
14-
13+
1514
@Environment(\.diffConfiguration) private var configuration
16-
15+
1716
private var backgroundColor: Color {
1817
switch line.type {
1918
case .added:
@@ -26,7 +25,7 @@ struct DiffLineView: View {
2625
return configuration.theme.headerBackground
2726
}
2827
}
29-
28+
3029
private var foregroundColor: Color {
3130
switch line.type {
3231
case .added:
@@ -39,7 +38,7 @@ struct DiffLineView: View {
3938
return configuration.theme.headerText
4039
}
4140
}
42-
41+
4342
private var linePrefix: String {
4443
switch line.type {
4544
case .added:
@@ -50,7 +49,7 @@ struct DiffLineView: View {
5049
return " "
5150
}
5251
}
53-
52+
5453
var body: some View {
5554
HStack(spacing: 0) {
5655
if configuration.showLineNumbers {
@@ -60,23 +59,31 @@ struct DiffLineView: View {
6059
.frame(width: 20, alignment: .trailing)
6160
.padding(.horizontal, 4)
6261
.background(configuration.theme.lineNumberBackground)
63-
62+
6463
Text(line.newLineNumber.map(String.init) ?? "")
6564
.font(.system(size: configuration.fontSize * 0.85, design: configuration.fontFamily))
6665
.foregroundColor(configuration.theme.lineNumberText)
6766
.frame(width: 20, alignment: .trailing)
6867
.padding(.horizontal, 4)
6968
.background(configuration.theme.lineNumberBackground)
7069
}
71-
70+
7271
HStack(alignment: .top, spacing: 0) {
7372
Text(linePrefix)
74-
.font(.system(size: configuration.fontSize, weight: configuration.fontWeight, design: configuration.fontFamily))
73+
.font(
74+
.system(
75+
size: configuration.fontSize, weight: configuration.fontWeight,
76+
design: configuration.fontFamily)
77+
)
7578
.foregroundColor(foregroundColor)
7679
.padding(.leading, configuration.contentPadding.leading)
77-
80+
7881
Text(line.content)
79-
.font(.system(size: configuration.fontSize, weight: configuration.fontWeight, design: configuration.fontFamily))
82+
.font(
83+
.system(
84+
size: configuration.fontSize, weight: configuration.fontWeight,
85+
design: configuration.fontFamily)
86+
)
8087
.foregroundColor(foregroundColor)
8188
.padding(.leading, 4)
8289
.padding(.trailing, configuration.contentPadding.trailing)
@@ -98,7 +105,7 @@ struct DiffLineView: View {
98105
newLineNumber: 3
99106
)
100107
)
101-
108+
102109
DiffLineView(
103110
line: DiffLine(
104111
type: .added,
@@ -107,7 +114,7 @@ struct DiffLineView: View {
107114
newLineNumber: 4
108115
)
109116
)
110-
117+
111118
DiffLineView(
112119
line: DiffLine(
113120
type: .context,
@@ -116,7 +123,7 @@ struct DiffLineView: View {
116123
newLineNumber: 5
117124
)
118125
)
119-
126+
120127
DiffLineView(
121128
line: DiffLine(
122129
type: .removed,
@@ -125,7 +132,7 @@ struct DiffLineView: View {
125132
newLineNumber: nil
126133
)
127134
)
128-
135+
129136
DiffLineView(
130137
line: DiffLine(
131138
type: .added,
@@ -135,5 +142,5 @@ struct DiffLineView: View {
135142
)
136143
)
137144
}
138-
.background(Color(UIColor.systemBackground))
145+
.background(Color(.systemBackground))
139146
}

Sources/gitdiff/Views/DiffRenderer.swift

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Created by Tornike Gomareli on 18.06.25.
66
//
77

8-
98
import SwiftUI
109

1110
/// A SwiftUI view that renders git diff output with syntax highlighting.
@@ -61,44 +60,44 @@ public struct DiffRenderer: View {
6160
.padding()
6261
}
6362
}
64-
.background(Color(UIColor.systemBackground))
63+
.background(Color(.systemBackground))
6564
}
6665
}
6766

6867
#Preview {
6968
let text = """
70-
diff --git a/example.swift b/example.swift
71-
index 1234567..abcdefg 100644
72-
--- a/example.swift
73-
+++ b/example.swift
74-
@@ -1,5 +1,6 @@
75-
import SwiftUI
76-
77-
struct ContentView: View {
78-
+ let title = "Hello World"
79-
var body: some View {
80-
- Text("Hello, World!")
81-
+ Text(title)
82-
}
83-
}
84-
diff --git a/AppDelegate.swift b/AppDelegate.swift
85-
index 2345678..bcdefgh 100644
86-
--- a/AppDelegate.swift
87-
+++ b/AppDelegate.swift
88-
@@ -10,8 +10,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
89-
func applicationDidFinishLaunching(_ notification: Notification) {
90-
// Insert code here to initialize your application
91-
+ setupApplication()
69+
diff --git a/example.swift b/example.swift
70+
index 1234567..abcdefg 100644
71+
--- a/example.swift
72+
+++ b/example.swift
73+
@@ -1,5 +1,6 @@
74+
75+
76+
struct ContentView: View {
77+
+ let title = "Hello World"
78+
var body: some View {
79+
- Text("Hello, World!")
80+
+ Text(title)
81+
}
9282
}
93-
94-
- func applicationWillTerminate(_ notification: Notification) {
95-
- // Insert code here to tear down your application
96-
+ private func setupApplication() {
97-
+ // Configure app settings
98-
+ print("Application setup complete")
83+
diff --git a/AppDelegate.swift b/AppDelegate.swift
84+
index 2345678..bcdefgh 100644
85+
--- a/AppDelegate.swift
86+
+++ b/AppDelegate.swift
87+
@@ -10,8 +10,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
88+
func applicationDidFinishLaunching(_ notification: Notification) {
89+
// Insert code here to initialize your application
90+
+ setupApplication()
91+
}
92+
93+
- func applicationWillTerminate(_ notification: Notification) {
94+
- // Insert code here to tear down your application
95+
+ private func setupApplication() {
96+
+ // Configure app settings
97+
+ print("Application setup complete")
98+
}
9999
}
100-
}
101-
"""
100+
"""
102101
// Simple usage with default GitHub theme
103102
DiffRenderer(diffText: text)
104103

0 commit comments

Comments
 (0)