@@ -1149,17 +1149,30 @@ func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {
1149
1149
for _ , diff := range diffs {
1150
1150
text := diff .Text
1151
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
+ }
1160
+
1152
1161
switch diff .Type {
1153
1162
case DiffInsert :
1154
1163
_ , _ = buff .WriteString ("\x1b [32m" )
1155
- text = strings .ReplaceAll (text , " " , "█" )
1156
- text = strings .ReplaceAll (text , "\n " , "⏎" )
1164
+ if ! containsCharacters {
1165
+ text = strings .ReplaceAll (text , " " , "█" )
1166
+ text = strings .ReplaceAll (text , "\n " , "⏎" )
1167
+ }
1157
1168
_ , _ = buff .WriteString (text )
1158
1169
_ , _ = buff .WriteString ("\x1b [0m" )
1159
1170
case DiffDelete :
1160
1171
_ , _ = buff .WriteString ("\x1b [31m" )
1161
- text = strings .ReplaceAll (text , " " , "█" )
1162
- text = strings .ReplaceAll (text , "\n " , "⏎" )
1172
+ if ! containsCharacters {
1173
+ text = strings .ReplaceAll (text , " " , "█" )
1174
+ text = strings .ReplaceAll (text , "\n " , "⏎" )
1175
+ }
1163
1176
_ , _ = buff .WriteString (text )
1164
1177
_ , _ = buff .WriteString ("\x1b [0m" )
1165
1178
case DiffEqual :
0 commit comments