@@ -1148,15 +1148,32 @@ func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {
1148
1148
var buff bytes.Buffer
1149
1149
for _ , diff := range diffs {
1150
1150
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
+ }
1151
1160
1152
1161
switch diff .Type {
1153
1162
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 )
1156
1169
_ , _ = buff .WriteString ("\x1b [0m" )
1157
1170
case DiffDelete :
1158
1171
_ , _ = 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 )
1160
1177
_ , _ = buff .WriteString ("\x1b [0m" )
1161
1178
case DiffEqual :
1162
1179
_ , _ = buff .WriteString (text )
0 commit comments