Open ghost opened 1 year ago
looks like it would just be like this:
func DiffText(diffs []Diff) string {
var buf strings.Builder
for _, diff := range diffs {
buf.WriteString(diff.Text)
}
return buf.String()
}
What output do you get from that? I just get the same text as the colored output without color. Which is meaningless because there are no +
or -
or any symbols to tell which text is added/removed in the diff:
text1 := `abc
x123
def
feg`
text2 := `abc
deg
feg
ooo`
diffs := dmp.DiffMain(text1, text2, false)
With the code above I get this output:
abc
x123
defg
feg
ooo
good catch, looks like this would do it:
func diff_text(diffs []Diff) string {
var b strings.Builder
for _, diff := range diffs {
switch diff.Type {
case DiffInsert:
b.WriteByte('+')
b.WriteString(diff.Text)
case DiffDelete:
b.WriteByte('-')
b.WriteString(diff.Text)
case DiffEqual:
b.WriteString(diff.Text)
}
}
return b.String()
}
I see these:
https://godocs.io/github.com/sergi/go-diff/diffmatchpatch#DiffMatchPatch.DiffPrettyHtml https://godocs.io/github.com/sergi/go-diff/diffmatchpatch#DiffMatchPatch.DiffPrettyText
how to create a diff without color?