@@ -1 +1,125 @@
1package diffview
1package diffview
4+ "github.com/aymanbagabas/go-udiff"
5+ "github.com/aymanbagabas/go-udiff/myers"
6+ "github.com/charmbracelet/lipgloss/v2"
17+ layoutUnified layout = iota + 1
21+// DiffView represents a view for displaying differences between two files.
22+type DiffView struct {
27+ baseStyle lipgloss.Style
34+ unified udiff.UnifiedDiff
38+// New creates a new DiffView with default settings.
39+func New() *DiffView {
41+ layout: layoutUnified,
42+ contextLines: udiff.DefaultContextLines,
46+// Unified sets the layout of the DiffView to unified.
47+func (dv *DiffView) Unified() *DiffView {
48+ dv.layout = layoutUnified
52+// Split sets the layout of the DiffView to split (side-by-side).
53+func (dv *DiffView) Split() *DiffView {
54+ dv.layout = layoutSplit
58+// Before sets the "before" file for the DiffView.
59+func (dv *DiffView) Before(path, content string) *DiffView {
60+ dv.before = file{path: path, content: content}
64+// After sets the "after" file for the DiffView.
65+func (dv *DiffView) After(path, content string) *DiffView {
66+ dv.after = file{path: path, content: content}
70+// ContextLines sets the number of context lines for the DiffView.
71+func (dv *DiffView) ContextLines(contextLines int) *DiffView {
72+ dv.contextLines = contextLines
76+// BaseStyle sets the base style for the DiffView.
77+// This is useful for setting a custom background color, for example.
78+func (dv *DiffView) BaseStyle(baseStyle lipgloss.Style) *DiffView {
79+ dv.baseStyle = baseStyle
83+// SyntaxHighlight sets whether to enable syntax highlighting in the DiffView.
84+func (dv *DiffView) SyntaxHighlight(highlight bool) *DiffView {
85+ dv.highlight = highlight
89+// Height sets the height of the DiffView.
90+func (dv *DiffView) Height(height int) *DiffView {
95+// Width sets the width of the DiffView.
96+func (dv *DiffView) Width(width int) *DiffView {
101+// String returns the string representation of the DiffView.
102+func (dv *DiffView) String() string {
107+ return dv.err.Error()
109+ return dv.unified.String()
112+func (dv *DiffView) compute() {
113+ dv.isComputed = true
114+ dv.edits = myers.ComputeEdits(
118+ dv.unified, dv.err = udiff.ToUnifiedDiff(