cdiff
generates line-by-line diff or word-by-word diff (like github) and formats with color.
import (
"github.com/gookit/color"
)
func main() {
diff := cdiff.Diff(string(oldDoc), string(newDoc), cdiff.WordByWord)
color.Print(diff.Unified(oldDocPath, newDocPath, 3, cdiff.GooKitColorTheme))
}
It returns diff information from oldText/newText. diffType
should be WordByWord
or LineByLine
.
It returns string representation of unified format.
keepLines
is like diff -U n
. No changed lines count around diffs.
theme
is a style text to create string representation. There is GooKitColorTheme
and HTMLTheme
.
GooKitColorTheme
has tags of github.com/gookit/color.
It doesn't omit unchanged line blocks instead of Unified()
.
It is similar to Format()
but it desn't have extra text like theme.
Apache 2