diff --git a/CHANGELOG.md b/CHANGELOG.md index 29400037cc..f28c91b62d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ ### Modules +- add a panel around diff previews when updating ([#3246](https://github.com/nf-core/tools/pull/3246)) + ### Subworkflows ### General diff --git a/nf_core/modules/modules_differ.py b/nf_core/modules/modules_differ.py index f9ba9d30c7..6b0781bb89 100644 --- a/nf_core/modules/modules_differ.py +++ b/nf_core/modules/modules_differ.py @@ -6,7 +6,9 @@ from pathlib import Path from typing import Dict, List, Union -from rich.console import Console +from rich import box +from rich.console import Console, Group, RenderableType +from rich.panel import Panel from rich.syntax import Syntax import nf_core.utils @@ -276,6 +278,7 @@ def print_diff( else: log.info(f"Changes in module '{Path(repo_path, module)}'") + panel_group: list[RenderableType] = [] for file, (diff_status, diff) in diffs.items(): if diff_status == ModulesDiffer.DiffEnum.UNCHANGED: # The files are identical @@ -293,7 +296,18 @@ def print_diff( # The file has changed log.info(f"Changes in '{Path(module, file)}':") # Pretty print the diff using the pygments diff lexer - console.print(Syntax("".join(diff), "diff", theme="ansi_dark", padding=1)) + syntax = Syntax("".join(diff), "diff", theme="ansi_dark", line_numbers=True) + panel_group.append(Panel(syntax, title=str(file), title_align="left", padding=0)) + console.print( + Panel( + Group(*panel_group), + title=f"[white]{str(module)}[/white]", + title_align="left", + padding=0, + border_style="blue", + box=box.HEAVY, + ) + ) @staticmethod def per_file_patch(patch_fn: Union[str, Path]) -> Dict[str, List[str]]: