Add a patch command

- Make it easy to apply the patches some tools produce.
This commit is contained in:
Andrew Hamilton 2025-06-21 14:41:06 +10:00
parent 99ed8efc43
commit 754143b395
4 changed files with 18 additions and 7 deletions

View file

@ -1,3 +1 @@
__version__ = "v2025.06.14" __version__ = "v2025.06.14"

View file

@ -88,6 +88,7 @@ KEYS_DOC = """Keys:
R - Refresh all reports of the current tool. R - Refresh all reports of the current tool.
f - Resize the focused pane to the full screen. (toggle) f - Resize the focused pane to the full screen. (toggle)
o - Open the current file with xdg-open. o - Open the current file with xdg-open.
p - Patch the current file. (When viewing a patch from a tool)
""" """
@ -786,6 +787,15 @@ class Screen:
in_green(f" at line {line_num}")]) in_green(f" at line {line_num}")])
subprocess.Popen(f"{self.editor_command} +{line_num} {path}", shell=True, subprocess.Popen(f"{self.editor_command} +{line_num} {path}", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def patch_file(self):
result = self._summary.get_selection()
if hasattr(result.tool, "patch_command") and result.tool.patch_command is not None:
path = result.path
path_colored = lscolors.path_colored(path)
self._log.log_message([in_green("Patching file: "), path_colored])
subprocess.run(f"{result.tool.patch_command} {path} | patch -p0", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
subprocess.run(["touch", path])
def toggle_status_style(self): def toggle_status_style(self):
self._summary.toggle_status_style(self._log) self._summary.toggle_status_style(self._log)
@ -915,7 +925,7 @@ class Screen:
tools.STATUS_TO_TERMSTR[widget.status] + divider + "line " + str(y+1)) tools.STATUS_TO_TERMSTR[widget.status] + divider + "line " + str(y+1))
_STATUS_BAR = highlight_chars(" *help *quit *t*a*b:focus *turn *log *edit *next *sort" _STATUS_BAR = highlight_chars(" *help *quit *t*a*b:focus *turn *log *edit *next *sort"
" *refresh *fullscreen *open", Log._GREEN_STYLE) " *refresh *fullscreen *open *patch", Log._GREEN_STYLE)
@functools.cache @functools.cache
def _get_partial_bar_chars(self, bar_transparency): def _get_partial_bar_chars(self, bar_transparency):
@ -963,9 +973,9 @@ class Screen:
terminal.RIGHT: cursor_right, terminal.PAGE_DOWN: cursor_page_down, terminal.RIGHT: cursor_right, terminal.PAGE_DOWN: cursor_page_down,
terminal.PAGE_UP: cursor_page_up, "s": toggle_order, terminal.HOME: cursor_home, terminal.PAGE_UP: cursor_page_up, "s": toggle_order, terminal.HOME: cursor_home,
terminal.END: cursor_end, "n": move_to_next_issue, "N": move_to_next_issue_of_tool, terminal.END: cursor_end, "n": move_to_next_issue, "N": move_to_next_issue_of_tool,
"e": edit_file, "q": quit_, terminal.ESC: quit_, terminal.CTRL_C: quit_, "e": edit_file, "p": patch_file, "q": quit_, terminal.ESC: quit_,
"r": refresh, "R": refresh_tool, "\t": toggle_focus, "f": toggle_fullscreen, terminal.CTRL_C: quit_, "r": refresh, "R": refresh_tool, "\t": toggle_focus,
"o": xdg_open} "f": toggle_fullscreen, "o": xdg_open}
def setup_inotify(root_path, loop, on_filesystem_event, exclude_filter): def setup_inotify(root_path, loop, on_filesystem_event, exclude_filter):

View file

@ -437,7 +437,7 @@ def git_log(path):
def make_tool_function(dependencies, command, url=None, error_status=None, def make_tool_function(dependencies, command, url=None, error_status=None,
has_color=False, timeout=None): has_color=False, timeout=None, patch_command=None):
if url is None: if url is None:
url = dependencies[0] url = dependencies[0]
command_parts = command.split() command_parts = command.split()
@ -448,6 +448,7 @@ def make_tool_function(dependencies, command, url=None, error_status=None,
def func(path): def func(path):
return _run_command(command_parts + [path], error_status, has_color, timeout) return _run_command(command_parts + [path], error_status, has_color, timeout)
func.command = command func.command = command
func.patch_command = patch_command
return func return func

View file

@ -96,12 +96,14 @@ tools_for_extensions = [
dependencies = ["black"] dependencies = ["black"]
url = "https://github.com/psf/black" url = "https://github.com/psf/black"
command = "black --check --diff --color" command = "black --check --diff --color"
patch_command = "black --diff"
has_color = true has_color = true
[isort] [isort]
dependencies = ["python3-isort", "python3-colorama"] dependencies = ["python3-isort", "python3-colorama"]
url = "https://pycqa.github.io/isort/" url = "https://pycqa.github.io/isort/"
command = "/usr/bin/python3 -m isort --check-only --diff --color" command = "/usr/bin/python3 -m isort --check-only --diff --color"
patch_command = "/usr/bin/python3 -m isort --diff"
has_color = true has_color = true
[perl_syntax] [perl_syntax]