Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions diffmatchpatch/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -1149,13 +1149,30 @@ func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {
for _, diff := range diffs {
text := diff.Text

var containsCharacters bool
// If the diff only consists of whitespace characters, then pretty-print the whiteshace
for _, char := range text {
if char != ' ' && char != '\n' {
containsCharacters = true
break
}
}

switch diff.Type {
case DiffInsert:
_, _ = buff.WriteString("\x1b[32m")
if !containsCharacters {
text = strings.ReplaceAll(text, " ", "█")
text = strings.ReplaceAll(text, "\n", "⏎")
}
_, _ = buff.WriteString(text)
_, _ = buff.WriteString("\x1b[0m")
case DiffDelete:
_, _ = buff.WriteString("\x1b[31m")
if !containsCharacters {
text = strings.ReplaceAll(text, " ", "█")
text = strings.ReplaceAll(text, "\n", "⏎")
}
_, _ = buff.WriteString(text)
_, _ = buff.WriteString("\x1b[0m")
case DiffEqual:
Expand Down