@@ -1148,15 +1148,32 @@ func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {
11481148 var buff bytes.Buffer
11491149 for _ , diff := range diffs {
11501150 text := diff .Text
1151+
1152+ var containsCharacters bool
1153+ // If the diff only consists of whitespace characters, then pretty-print the whiteshace
1154+ for _ , char := range text {
1155+ if char != ' ' && char != '\n' {
1156+ containsCharacters = true
1157+ break
1158+ }
1159+ }
11511160
11521161 switch diff .Type {
11531162 case DiffInsert :
1154- _ , _ = buff .WriteString ("\x1b [32m" )
1155- _ , _ = buff .WriteString (text )
1163+ _ , _ = buff .WriteString ("\x1b [32m" )
1164+ if ! containsCharacters {
1165+ text = strings .ReplaceAll (text , " " , "█" )
1166+ text = strings .ReplaceAll (text , "\n " , "⏎" )
1167+ }
1168+ _ , _ = buff .WriteString (text )
11561169 _ , _ = buff .WriteString ("\x1b [0m" )
11571170 case DiffDelete :
11581171 _ , _ = buff .WriteString ("\x1b [31m" )
1159- _ , _ = buff .WriteString (text )
1172+ if ! containsCharacters {
1173+ text = strings .ReplaceAll (text , " " , "█" )
1174+ text = strings .ReplaceAll (text , "\n " , "⏎" )
1175+ }
1176+ _ , _ = buff .WriteString (text )
11601177 _ , _ = buff .WriteString ("\x1b [0m" )
11611178 case DiffEqual :
11621179 _ , _ = buff .WriteString (text )
0 commit comments