import Foundation /// One line of a unified diff: unchanged, removed or added. public enum DiffSign: String, Sendable, Equatable { case same = " " case removed = "-" case added = "+" } public struct DiffRow: Sendable, Equatable { public var sign: DiffSign /// 1-based line number in the original; nil for an added line. public var oldNo: Int? /// 1-based line number in the updated text; nil for a removed line. public var newNo: Int? public var text: String public init(sign: DiffSign, oldNo: Int?, newNo: Int?, text: String) { self.sign = sign self.oldNo = oldNo self.newNo = newNo self.text = text } } public enum LineMark: String, Sendable, Equatable { case added case removed } /// One line of one side of the diff, with its 1-based number in that side. public struct SideLine: Sendable, Equatable { public var no: Int public var text: String public var mark: LineMark? public init(no: Int, text: String, mark: LineMark? = nil) { self.no = no self.text = text self.mark = mark } } /// A row of the side-by-side view; a nil side is the filler opposite an unpaired add or remove. public struct SplitRow: Sendable, Equatable { public var left: SideLine? public var right: SideLine? public init(left: SideLine?, right: SideLine?) { self.left = left self.right = right } } /// Everything the Actual view and the Diff need, derived from one (original, updated) pair. public struct Diff: Sendable, Equatable { public var rows: [DiffRow] public var left: [SideLine] public var right: [SideLine] public var split: [SplitRow] public var added: Int public var removed: Int public var isDeletedFile: Bool public var isAddedFile: Bool public var original: String public var updated: String /// Built from a change over the diff cap: the texts are empty, not the file. public var isTooBig = false public init( rows: [DiffRow], left: [SideLine], right: [SideLine], split: [SplitRow], added: Int, removed: Int, isDeletedFile: Bool, isAddedFile: Bool, original: String, updated: String ) { self.rows = rows self.left = left self.right = right self.split = split self.added = added self.removed = removed self.isDeletedFile = isDeletedFile self.isAddedFile = isAddedFile self.original = original self.updated = updated } } /// Which half of a file's changes a Diff shows: HEAD vs index, or index vs disk. /// Absent (nil) means the whole file, HEAD vs disk, which Actual always shows. public enum DiffSide: String, Codable, Sendable, Equatable { case staged case unstaged } /// How a line is painted in the read-only editor panes. public enum ViewLineStyle: String, Sendable, Equatable { /// Full tint: a line the change added (Actual view). case added } /// Where a removed run's rule sits, since removed lines own no line of their own in Actual. public enum GapEdge: String, Sendable, Equatable { case above case below } /// A line descriptor for the editor panes. public struct ViewLine: Sendable, Equatable { public var no: Int? public var text: String public var sign: DiffSign? public var style: ViewLineStyle? public var gap: GapEdge? public init(no: Int?, text: String, sign: DiffSign? = nil, style: ViewLineStyle? = nil, gap: GapEdge? = nil) { self.no = no self.text = text self.sign = sign self.style = style self.gap = gap } }