From f2b6f3bb008e5b14110d8fe57b028cc53f1ec77b Mon Sep 17 00:00:00 2001 From: Scriptim Date: Sun, 3 Nov 2024 23:39:31 +0100 Subject: [PATCH] Add clickable links to file names in the printed report --- PFERD/crawl/crawler.py | 4 ++++ PFERD/pferd.py | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/PFERD/crawl/crawler.py b/PFERD/crawl/crawler.py index dd500e6..fda1307 100644 --- a/PFERD/crawl/crawler.py +++ b/PFERD/crawl/crawler.py @@ -258,6 +258,10 @@ class Crawler(ABC): def prev_report(self) -> Optional[Report]: return self._output_dir.prev_report + @property + def output_dir(self) -> OutputDirectory: + return self._output_dir + @staticmethod async def gather(awaitables: Sequence[Awaitable[Any]]) -> List[Any]: """ diff --git a/PFERD/pferd.py b/PFERD/pferd.py index b30a04a..3ec459d 100644 --- a/PFERD/pferd.py +++ b/PFERD/pferd.py @@ -1,4 +1,4 @@ -from pathlib import Path +from pathlib import Path, PurePath from typing import Dict, List, Optional from rich.markup import escape @@ -168,19 +168,23 @@ class Pferd: log.report("") log.report(f"[bold bright_cyan]Report[/] for {escape(name)}") + def fmt_path_link(relative_path: PurePath) -> str: + link = f"file://{crawler.output_dir.resolve(relative_path).absolute()}" + return f"[link={link}]{fmt_path(relative_path)}[/link]" + something_changed = False for path in sorted(crawler.report.added_files): something_changed = True - log.report(f" [bold bright_green]Added[/] {fmt_path(path)}") + log.report(f" [bold bright_green]Added[/] {fmt_path_link(path)}") for path in sorted(crawler.report.changed_files): something_changed = True - log.report(f" [bold bright_yellow]Changed[/] {fmt_path(path)}") + log.report(f" [bold bright_yellow]Changed[/] {fmt_path_link(path)}") for path in sorted(crawler.report.deleted_files): something_changed = True log.report(f" [bold bright_magenta]Deleted[/] {fmt_path(path)}") for path in sorted(crawler.report.not_deleted_files): something_changed = True - log.report_not_deleted(f" [bold bright_magenta]Not deleted[/] {fmt_path(path)}") + log.report_not_deleted(f" [bold bright_magenta]Not deleted[/] {fmt_path_link(path)}") for warning in crawler.report.encountered_warnings: something_changed = True