From 754143b395bbf35918a2808998e851b36bce5c4c Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Sat, 21 Jun 2025 14:41:06 +1000 Subject: [PATCH] Add a patch command - Make it easy to apply the patches some tools produce. --- eris/__init__.py | 2 -- eris/__main__.py | 18 ++++++++++++++---- eris/tools.py | 3 ++- eris/tools.toml | 2 ++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/eris/__init__.py b/eris/__init__.py index 9d3e284..60fc7e5 100644 --- a/eris/__init__.py +++ b/eris/__init__.py @@ -1,3 +1 @@ - - __version__ = "v2025.06.14" diff --git a/eris/__main__.py b/eris/__main__.py index c46c9ae..21e7de7 100755 --- a/eris/__main__.py +++ b/eris/__main__.py @@ -88,6 +88,7 @@ KEYS_DOC = """Keys: R - Refresh all reports of the current tool. f - Resize the focused pane to the full screen. (toggle) 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}…")]) subprocess.Popen(f"{self.editor_command} +{line_num} {path}", shell=True, 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): self._summary.toggle_status_style(self._log) @@ -915,7 +925,7 @@ class Screen: 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" - " *refresh *fullscreen *open", Log._GREEN_STYLE) + " *refresh *fullscreen *open *patch", Log._GREEN_STYLE) @functools.cache 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.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, - "e": edit_file, "q": quit_, terminal.ESC: quit_, terminal.CTRL_C: quit_, - "r": refresh, "R": refresh_tool, "\t": toggle_focus, "f": toggle_fullscreen, - "o": xdg_open} + "e": edit_file, "p": patch_file, "q": quit_, terminal.ESC: quit_, + terminal.CTRL_C: quit_, "r": refresh, "R": refresh_tool, "\t": toggle_focus, + "f": toggle_fullscreen, "o": xdg_open} def setup_inotify(root_path, loop, on_filesystem_event, exclude_filter): diff --git a/eris/tools.py b/eris/tools.py index a292637..1daa6f4 100755 --- a/eris/tools.py +++ b/eris/tools.py @@ -437,7 +437,7 @@ def git_log(path): 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: url = dependencies[0] command_parts = command.split() @@ -448,6 +448,7 @@ def make_tool_function(dependencies, command, url=None, error_status=None, def func(path): return _run_command(command_parts + [path], error_status, has_color, timeout) func.command = command + func.patch_command = patch_command return func diff --git a/eris/tools.toml b/eris/tools.toml index 9bf91d9..0f61767 100644 --- a/eris/tools.toml +++ b/eris/tools.toml @@ -96,12 +96,14 @@ tools_for_extensions = [ dependencies = ["black"] url = "https://github.com/psf/black" command = "black --check --diff --color" + patch_command = "black --diff" has_color = true [isort] dependencies = ["python3-isort", "python3-colorama"] url = "https://pycqa.github.io/isort/" command = "/usr/bin/python3 -m isort --check-only --diff --color" + patch_command = "/usr/bin/python3 -m isort --diff" has_color = true [perl_syntax]