Documentation
¶
Overview ¶
Package diff provides word-level diff visualization with context-aware hunk merging.
This package is a wrapper around github.com/sergi/go-diff/diffmatchpatch that enhances the diff output by:
- Tokenizing text into words, whitespace, and punctuation
- Adding configurable context around changes
- Merging nearby changes into unified hunks
- Rendering diffs as HTML (with <del>/<ins> tags) or colored terminal output
Index ¶
Constants ¶
View Source
const ( // DelBgColor is the ANSI escape code for deleted text background. DelBgColor = "\033[48;2;255;200;200m" // InsBgColor is the ANSI escape code for inserted text background. InsBgColor = "\033[48;2;200;255;200m" // ResetBgColor is the ANSI escape code to reset all formatting to default. ResetBgColor = "\033[0m" )
Variables ¶
View Source
var ContextWordsDefault = 20
ContextWordsDefault is the default number of words to show around each change.
Functions ¶
This section is empty.
Types ¶
type Diff ¶
type Diff struct {
Text1, Text2 string
ContextWords int
Diff []diffmatchpatch.Diff
}
Diff represents a computed difference between two texts with rendering capabilities.
func Compute ¶
Compute calculates the difference between two texts and returns a diff object. The optional ContextWords parameter controls how many words of context to show around each change. If not provided, ContextWordsDefault is used.
Usage:
diffHTML := diff.Compute("old text", "new text").HTML()
diffString := diff.Compute("old text", "new text", 5).String() // custom context size
func ComputeFromPatch ¶
ComputeFromPatch applies a patch to text1 and computes the difference.
Click to show internal directories.
Click to hide internal directories.