Skip to content

cdiff generates line-by-line diff or word-by-word diff (like github) and formats with color.

License

Notifications You must be signed in to change notification settings

shibukawa/cdiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cdiff

GoDoc

cdiff generates line-by-line diff or word-by-word diff (like github) and formats with color.

screenshot

Usage

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))
}

Reference

func Diff(oldText, newText string, diffType DiffType) Result

It returns diff information from oldText/newText. diffType should be WordByWord or LineByLine.

Result.Unified(oldDocPath, newDocPath string, keepLines int, theme map[Tag]string) string

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.

Result.Format(theme map[Tag]string) string

It doesn't omit unchanged line blocks instead of Unified().

Result.String() sring

It is similar to Format() but it desn't have extra text like theme.

License

Apache 2

About

cdiff generates line-by-line diff or word-by-word diff (like github) and formats with color.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages