-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-133722: Add Difflib theme to _colorize
and 'color' option to difflib.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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 10 commits
5c5b248
fdc0fa0
fcdd7ab
0e9b070
7c31749
66475a2
dbf0547
a72012e
2a3d818
252982e
3422fa7
bffdd71
3255866
c48a6ac
8ca50fa
eb0e81e
f7b34c3
fb092b0
734b0bc
8a10e40
57b80d1
c235425
387cfe6
833d86a
25f9d80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -207,6 +207,17 @@ class Unittest(ThemeSection): | |||||||||||||||||
reset: str = ANSIColors.RESET | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
@dataclass(frozen=True) | ||||||||||||||||||
class Difflib(ThemeSection): | ||||||||||||||||||
dougthor42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
"""A 'git diff'-like theme for `difflib.unified_diff`.""" | ||||||||||||||||||
header: str = ANSIColors.BOLD # eg "---" and "+++" lines | ||||||||||||||||||
hunk: str = ANSIColors.CYAN # the "@@" lines | ||||||||||||||||||
equal: str = ANSIColors.RESET # context lines | ||||||||||||||||||
insert: str = ANSIColors.GREEN | ||||||||||||||||||
delete: str = ANSIColors.RED | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opted to use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, maybe the Git-like terms if they're going to be more familiar with people and if the Where does Git mention them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall they are defined in the GNU unified diff detailed description. The
Though sometimes it uses "deleted" instead of "removed":
I've gone ahead and switched to the GNU unified diff terms prior to the requested sorting. Also, to keep consistent with the other dataclass attributes (which are not currently sorted), the |
||||||||||||||||||
reset: str = ANSIColors.RESET | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
@dataclass(frozen=True) | ||||||||||||||||||
class Theme: | ||||||||||||||||||
"""A suite of themes for all sections of Python. | ||||||||||||||||||
|
@@ -218,6 +229,7 @@ class Theme: | |||||||||||||||||
syntax: Syntax = field(default_factory=Syntax) | ||||||||||||||||||
traceback: Traceback = field(default_factory=Traceback) | ||||||||||||||||||
8000 unittest: Unittest = field(default_factory=Unittest) | ||||||||||||||||||
difflib: Difflib = field(default_factory=Difflib) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm very slightly concerned about sorting when the dataclasses aren't Should I update the dataclass decorator to include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's ask @ambv about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Done |
||||||||||||||||||
|
||||||||||||||||||
def copy_with( | ||||||||||||||||||
self, | ||||||||||||||||||
|
@@ -226,6 +238,7 @@ def copy_with( | |||||||||||||||||
syntax: Syntax | None = None, | ||||||||||||||||||
traceback: Traceback | None = None, | ||||||||||||||||||
unittest: Unittest | None = None, | ||||||||||||||||||
difflib: Difflib | None = None, | ||||||||||||||||||
dougthor42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
) -> Self: | ||||||||||||||||||
"""Return a new Theme based on this instance with some sections replaced. | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -237,6 +250,7 @@ def copy_with( | |||||||||||||||||
syntax=syntax or self.syntax, | ||||||||||||||||||
traceback=traceback or self.traceback, | ||||||||||||||||||
unittest=unittest or self.unittest, | ||||||||||||||||||
difflib=difflib or self.difflib, | ||||||||||||||||||
dougthor42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
@classmethod | ||||||||||||||||||
|
@@ -252,6 +266,7 @@ def no_colors(cls) -> Self: | |||||||||||||||||
syntax=Syntax.no_colors(), | ||||||||||||||||||
traceback=Traceback.no_colors(), | ||||||||||||||||||
unittest=Unittest.no_colors(), | ||||||||||||||||||
difflib=Difflib.no_colors(), | ||||||||||||||||||
dougthor42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,2 @@ | ||||||
Added a ``color`` option to :func:`difflib.unified_diff` that injects ANSI color | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still todo :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops! |
||||||
codes to mimic ``git diff`` colors. |
Uh oh!
There was an error while loading. Please reload this page.