Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-133722: Add Difflib theme to_colorize
and 'color' option todifflib.unified_diff
#133725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
dougthor42 wants to merge21 commits intopython:mainChoose a base branch fromdougthor42:difflib-color-gh133722
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+72 −9
Open
Changes from1 commit
Commits
Show all changes
21 commits Select commitHold shift + click to select a range
5c5b248
Add test case
dougthor42fdc0fa0
Add 'color' arg to difflib.unified_diff.
dougthor42fcdd7ab
Update docs and ACKs
dougthor420e9b070
blurb
dougthor427c31749
fixup to follow convention
dougthor4266475a2
Add 'Difflib' theme
dougthor42dbf0547
fixup tests
dougthor42a72012e
Switch to using themes. So easy!
dougthor422a3d818
use 'next' in versionchanged docs
dougthor42252982e
turns out 'git diff' adds reset to the start and end of context lines
dougthor423422fa7
Use GNU unified diff terms
dougthor42bffdd71
move class
dougthor423255866
kw-only the 'color' arg
dougthor42c48a6ac
Doc formatting updates
dougthor428ca50fa
Sort the things that are safe to sort without kw_only=True
dougthor42eb0e81e
Update what's new
dougthor42f7b34c3
Merge remote-tracking branch 'upstream/main' into difflib-color-gh133722
dougthor42fb092b0
fixup docs
dougthor42734b0bc
fixup docs
dougthor428a10e40
Code review: docs, whatsnew, f-strings, news
dougthor4257b80d1
force_colorized
dougthor42File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Switch to using themes. So easy!
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commita72012e17f7da6de0156a9f684963b2623c99edf
There are no files selected for viewing
28 changes: 10 additions & 18 deletionsLib/difflib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -30,6 +30,7 @@ | ||
'Differ','IS_CHARACTER_JUNK', 'IS_LINE_JUNK', 'context_diff', | ||
'unified_diff', 'diff_bytes', 'HtmlDiff', 'Match'] | ||
from _colorize import can_colorize, get_theme | ||
from heapq import nlargest as _nlargest | ||
from collections import namedtuple as _namedtuple | ||
from types import GenericAlias | ||
@@ -1137,14 +1138,10 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='', | ||
four | ||
""" | ||
if color and can_colorize(): | ||
t = get_theme(force_color=True).difflib | ||
else: | ||
t = get_theme(force_no_color=True).difflib | ||
_check_types(a, b, fromfile, tofile, fromfiledate, tofiledate, lineterm) | ||
started = False | ||
@@ -1153,16 +1150,13 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='', | ||
started = True | ||
fromdate = '\t{}'.format(fromfiledate) if fromfiledate else '' | ||
todate = '\t{}'.format(tofiledate) if tofiledate else '' | ||
yield '{}--- {}{}{}{}'.format(t.header, fromfile, fromdate, lineterm, t.reset) | ||
yield '{}+++ {}{}{}{}'.format(t.header, tofile, todate, lineterm, t.reset) | ||
hugovk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
first, last = group[0], group[-1] | ||
file1_range = _format_range_unified(first[1], last[2]) | ||
file2_range = _format_range_unified(first[3], last[4]) | ||
yield '{}@@ -{} +{} @@{}{}'.format(t.hunk, file1_range, file2_range, lineterm, t.reset) | ||
hugovk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
for tag, i1, i2, j1, j2 in group: | ||
if tag == 'equal': | ||
@@ -1171,12 +1165,10 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='', | ||
continue | ||
if tag in {'replace', 'delete'}: | ||
for line in a[i1:i2]: | ||
yield f'{t.delete}-{line}{t.reset}' | ||
if tag in {'replace', 'insert'}: | ||
for line in b[j1:j2]: | ||
yield f'{t.insert}+{line}{t.reset}' | ||
######################################################################## | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.