Skip to content

Commit 252982e

Browse files
committed
turns out 'git diff' adds reset to the start and end of context lines
1 parent 2a3d818 commit 252982e

3 files changed

Lines changed: 3 additions & 2 deletions

File tree

Lib/_colorize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class Difflib(ThemeSection):
212212
"""A 'git diff'-like theme for `difflib.unified_diff`."""
213213
header: str = ANSIColors.BOLD # eg "---" and "+++" lines
214214
hunk: str = ANSIColors.CYAN # the "@@" lines
215+
equal: str = ANSIColors.RESET # context lines
215216
insert: str = ANSIColors.GREEN
216217
delete: str = ANSIColors.RED
217218
reset: str = ANSIColors.RESET

Lib/difflib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='',
11611161
for tag, i1, i2, j1, j2 in group:
11621162
if tag == 'equal':
11631163
for line in a[i1:i2]:
1164-
yield ' ' + line
1164+
yield f'{t.equal} {line}{t.reset}'
11651165
continue
11661166
if tag in {'replace', 'delete'}:
11671167
for line in a[i1:i2]:

Lib/test/test_difflib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def test_unified_diff_colored_output(self):
366366
"\033[36m@@ -1,2 +1,2 @@\033[0m",
367367
"\033[31m-one\033[0m",
368368
"\033[32m+two\033[0m",
369-
" three",
369+
"\033[0m three\033[0m",
370370
]
371371
self.assertEqual(expect, actual)
372372

0 commit comments

Comments
 (0)