From 245900f79e9f773b4c599b1deb3e82316641353e Mon Sep 17 00:00:00 2001 From: Tornike Gomareli <24585160+tornikegomareli@users.noreply.github.com> Date: Wed, 18 Jun 2025 19:42:42 +0400 Subject: [PATCH 1/2] fix: remove docc --- Package.swift | 3 --- Sources/gitdiff/gitdiff.docc/gitdiff.md | 25 ------------------------- 2 files changed, 28 deletions(-) delete mode 100644 Sources/gitdiff/gitdiff.docc/gitdiff.md diff --git a/Package.swift b/Package.swift index 14b5170..f200f90 100644 --- a/Package.swift +++ b/Package.swift @@ -13,9 +13,6 @@ let package = Package( name: "gitdiff", targets: ["gitdiff"]), ], - dependencies: [ - .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), - ], targets: [ .target( name: "gitdiff" diff --git a/Sources/gitdiff/gitdiff.docc/gitdiff.md b/Sources/gitdiff/gitdiff.docc/gitdiff.md deleted file mode 100644 index cbceb13..0000000 --- a/Sources/gitdiff/gitdiff.docc/gitdiff.md +++ /dev/null @@ -1,25 +0,0 @@ -# ``gitdiff`` - -A SwiftUI library for rendering git diff output with customizable themes and formatting. - -## Overview - -gitdiff provides a simple way to display git diff output in your SwiftUI applications with syntax highlighting and customizable themes. - -## Topics - -### Essentials - -- ``DiffRenderer`` -- ``DiffConfiguration`` -- ``DiffTheme`` - -### Configuration - -- ``DiffEnvironment`` - -### Models - -- ``DiffFile`` -- ``DiffHunk`` -- ``DiffLine`` \ No newline at end of file From daf1988aa2dd75727c3fe618a70038ec2cb0c1c5 Mon Sep 17 00:00:00 2001 From: Tornike Gomareli <24585160+tornikegomareli@users.noreply.github.com> Date: Wed, 18 Jun 2025 20:02:09 +0400 Subject: [PATCH 2/2] remove uikit --- Sources/gitdiff/Views/DiffFileView.swift | 37 ++++++++------ Sources/gitdiff/Views/DiffLineView.swift | 39 +++++++++------ Sources/gitdiff/Views/DiffRenderer.swift | 63 ++++++++++++------------ 3 files changed, 75 insertions(+), 64 deletions(-) diff --git a/Sources/gitdiff/Views/DiffFileView.swift b/Sources/gitdiff/Views/DiffFileView.swift index 43d9796..cf12407 100644 --- a/Sources/gitdiff/Views/DiffFileView.swift +++ b/Sources/gitdiff/Views/DiffFileView.swift @@ -5,28 +5,27 @@ // Created by Tornike Gomareli on 18.06.25. // - import SwiftUI /// View for rendering a single file's diff struct DiffFileView: View { let file: DiffFile - + @Environment(\.diffConfiguration) private var configuration - + var body: some View { VStack(alignment: .leading, spacing: 0) { HStack { Image(systemName: "doc.text") .foregroundColor(configuration.theme.fileHeaderText) - + Text(file.displayName) .font(.system(.headline, design: configuration.fontFamily)) .fontWeight(.bold) .foregroundColor(configuration.theme.fileHeaderText) - + Spacer() - + if file.isBinary { Text("Binary file") .font(.caption) @@ -39,7 +38,7 @@ struct DiffFileView: View { } .padding() .background(configuration.theme.fileHeaderBackground) - + if file.isBinary { Text("Binary file not shown") .font(.system(size: configuration.fontSize, design: configuration.fontFamily)) @@ -55,7 +54,7 @@ struct DiffFileView: View { .padding(.vertical, 4) .frame(maxWidth: .infinity, alignment: .leading) .background(configuration.theme.headerBackground) - + VStack(spacing: configuration.lineSpacing.value) { ForEach(hunk.lines) { line in DiffLineView(line: line) @@ -86,15 +85,21 @@ struct DiffFileView: View { lines: [ DiffLine(type: .context, content: "import SwiftUI", oldLineNumber: 1, newLineNumber: 1), DiffLine(type: .context, content: "", oldLineNumber: 2, newLineNumber: 2), - DiffLine(type: .context, content: "struct ContentView: View {", oldLineNumber: 3, newLineNumber: 3), - DiffLine(type: .added, content: " let title = \"Hello World\"", oldLineNumber: nil, newLineNumber: 4), - DiffLine(type: .context, content: " var body: some View {", oldLineNumber: 4, newLineNumber: 5), - DiffLine(type: .removed, content: " Text(\"Hello, World!\")", oldLineNumber: 5, newLineNumber: nil), + DiffLine( + type: .context, content: "struct ContentView: View {", oldLineNumber: 3, newLineNumber: 3), + DiffLine( + type: .added, content: " let title = \"Hello World\"", oldLineNumber: nil, + newLineNumber: 4), + DiffLine( + type: .context, content: " var body: some View {", oldLineNumber: 4, newLineNumber: 5), + DiffLine( + type: .removed, content: " Text(\"Hello, World!\")", oldLineNumber: 5, + newLineNumber: nil), DiffLine(type: .added, content: " Text(title)", oldLineNumber: nil, newLineNumber: 6), - DiffLine(type: .added, content: "}", oldLineNumber: nil, newLineNumber: 7) + DiffLine(type: .added, content: "}", oldLineNumber: nil, newLineNumber: 7), ] ) - + let sampleFile = DiffFile( oldPath: "example.swift", newPath: "example.swift", @@ -102,8 +107,8 @@ struct DiffFileView: View { isBinary: false, isRenamed: false ) - + DiffFileView(file: sampleFile) .padding() - .background(Color(UIColor.systemBackground)) + .background(Color(.systemBackground)) } diff --git a/Sources/gitdiff/Views/DiffLineView.swift b/Sources/gitdiff/Views/DiffLineView.swift index 00f82b8..0fffed3 100644 --- a/Sources/gitdiff/Views/DiffLineView.swift +++ b/Sources/gitdiff/Views/DiffLineView.swift @@ -5,15 +5,14 @@ // Created by Tornike Gomareli on 18.06.25. // - import SwiftUI /// View for rendering a single diff line with GitHub-style formatting struct DiffLineView: View { let line: DiffLine - + @Environment(\.diffConfiguration) private var configuration - + private var backgroundColor: Color { switch line.type { case .added: @@ -26,7 +25,7 @@ struct DiffLineView: View { return configuration.theme.headerBackground } } - + private var foregroundColor: Color { switch line.type { case .added: @@ -39,7 +38,7 @@ struct DiffLineView: View { return configuration.theme.headerText } } - + private var linePrefix: String { switch line.type { case .added: @@ -50,7 +49,7 @@ struct DiffLineView: View { return " " } } - + var body: some View { HStack(spacing: 0) { if configuration.showLineNumbers { @@ -60,7 +59,7 @@ struct DiffLineView: View { .frame(width: 20, alignment: .trailing) .padding(.horizontal, 4) .background(configuration.theme.lineNumberBackground) - + Text(line.newLineNumber.map(String.init) ?? "") .font(.system(size: configuration.fontSize * 0.85, design: configuration.fontFamily)) .foregroundColor(configuration.theme.lineNumberText) @@ -68,15 +67,23 @@ struct DiffLineView: View { .padding(.horizontal, 4) .background(configuration.theme.lineNumberBackground) } - + HStack(alignment: .top, spacing: 0) { Text(linePrefix) - .font(.system(size: configuration.fontSize, weight: configuration.fontWeight, design: configuration.fontFamily)) + .font( + .system( + size: configuration.fontSize, weight: configuration.fontWeight, + design: configuration.fontFamily) + ) .foregroundColor(foregroundColor) .padding(.leading, configuration.contentPadding.leading) - + Text(line.content) - .font(.system(size: configuration.fontSize, weight: configuration.fontWeight, design: configuration.fontFamily)) + .font( + .system( + size: configuration.fontSize, weight: configuration.fontWeight, + design: configuration.fontFamily) + ) .foregroundColor(foregroundColor) .padding(.leading, 4) .padding(.trailing, configuration.contentPadding.trailing) @@ -98,7 +105,7 @@ struct DiffLineView: View { newLineNumber: 3 ) ) - + DiffLineView( line: DiffLine( type: .added, @@ -107,7 +114,7 @@ struct DiffLineView: View { newLineNumber: 4 ) ) - + DiffLineView( line: DiffLine( type: .context, @@ -116,7 +123,7 @@ struct DiffLineView: View { newLineNumber: 5 ) ) - + DiffLineView( line: DiffLine( type: .removed, @@ -125,7 +132,7 @@ struct DiffLineView: View { newLineNumber: nil ) ) - + DiffLineView( line: DiffLine( type: .added, @@ -135,5 +142,5 @@ struct DiffLineView: View { ) ) } - .background(Color(UIColor.systemBackground)) + .background(Color(.systemBackground)) } diff --git a/Sources/gitdiff/Views/DiffRenderer.swift b/Sources/gitdiff/Views/DiffRenderer.swift index 9e0d730..bac5a91 100644 --- a/Sources/gitdiff/Views/DiffRenderer.swift +++ b/Sources/gitdiff/Views/DiffRenderer.swift @@ -5,7 +5,6 @@ // Created by Tornike Gomareli on 18.06.25. // - import SwiftUI /// A SwiftUI view that renders git diff output with syntax highlighting. @@ -61,44 +60,44 @@ public struct DiffRenderer: View { .padding() } } - .background(Color(UIColor.systemBackground)) + .background(Color(.systemBackground)) } } #Preview { let text = """ -diff --git a/example.swift b/example.swift -index 1234567..abcdefg 100644 ---- a/example.swift -+++ b/example.swift -@@ -1,5 +1,6 @@ - import SwiftUI - - struct ContentView: View { -+ let title = "Hello World" - var body: some View { -- Text("Hello, World!") -+ Text(title) - } - } -diff --git a/AppDelegate.swift b/AppDelegate.swift -index 2345678..bcdefgh 100644 ---- a/AppDelegate.swift -+++ b/AppDelegate.swift -@@ -10,8 +10,10 @@ class AppDelegate: NSObject, NSApplicationDelegate { - func applicationDidFinishLaunching(_ notification: Notification) { - // Insert code here to initialize your application -+ setupApplication() + diff --git a/example.swift b/example.swift + index 1234567..abcdefg 100644 + --- a/example.swift + +++ b/example.swift + @@ -1,5 +1,6 @@ + + + struct ContentView: View { + + let title = "Hello World" + var body: some View { + - Text("Hello, World!") + + Text(title) + } } - -- func applicationWillTerminate(_ notification: Notification) { -- // Insert code here to tear down your application -+ private func setupApplication() { -+ // Configure app settings -+ print("Application setup complete") + diff --git a/AppDelegate.swift b/AppDelegate.swift + index 2345678..bcdefgh 100644 + --- a/AppDelegate.swift + +++ b/AppDelegate.swift + @@ -10,8 +10,10 @@ class AppDelegate: NSObject, NSApplicationDelegate { + func applicationDidFinishLaunching(_ notification: Notification) { + // Insert code here to initialize your application + + setupApplication() + } + + - func applicationWillTerminate(_ notification: Notification) { + - // Insert code here to tear down your application + + private func setupApplication() { + + // Configure app settings + + print("Application setup complete") + } } - } -""" + """ // Simple usage with default GitHub theme DiffRenderer(diffText: text)