What are people's thoughts on adding a color: bool arg to difflib.unified_diff so that it injects ANSI terminal codes to color things in the way that git diff would?
New API:
difflib.unified_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n', color=False)
Open questions:
I'd be happy to tackle this. Excluding tests, it looks to be O(20 LOC) changes.
$ cat python mydiff.py cat: python: No such file or directory import difflib import pathlib file1 = pathlib.Path("a.txt") file2 = pathlib.Path("b.txt") udiff = difflib.unified_diff( file1.read_text().splitlines(), file2.read_text().splitlines(), fromfile=str(file1), tofile=str(file2), ) for line in udiff: print(line) $ python mydiff.py --- a.txt +++ b.txt @@ -1,3 +1,3 @@ 1a -2b 3c +4d
This is a minor feature, which does not need previous discussion elsewhere
No response
Add 'color' arg to difflib.unified_diff.
gh-133722: Add Difflib theme to `_colorize` and 'color' option to `di…
pythongh-133722: Add Difflib theme to `_colorize` and 'color' option …
Activity
Add 'color' arg to difflib.unified_diff.
gh-133722: Add Difflib theme to `_colorize` and 'color' option to `di…
pythongh-133722: Add Difflib theme to `_colorize` and 'color' option …