Skip to content
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

Add hyperlink to console output #1613

Merged
merged 2 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion coverage/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import re
import shutil
import string # pylint: disable=deprecated-module
import sys

from dataclasses import dataclass
from typing import Any, Dict, Iterable, List, Optional, Tuple, TYPE_CHECKING, cast
Expand Down Expand Up @@ -493,7 +494,14 @@ def index_file(self, first_html: str, final_html: str) -> None:

index_file = os.path.join(self.directory, "index.html")
write_html(index_file, html)
self.coverage._message(f"Wrote HTML report to {index_file}")

if sys.stdout.isatty():
file_path = f"file://{os.path.abspath(index_file)}"
print_path = f"\033]8;;{file_path}\a{index_file}\033]8;;\a"
else:
print_path = index_file

self.coverage._message(f"Wrote HTML report to {print_path}")

# Write the latest hashes for next time.
self.incr.write()
Expand Down
8 changes: 7 additions & 1 deletion coverage/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import annotations

import os
import sys

from typing import Callable, Iterable, Iterator, IO, Optional, Tuple, TYPE_CHECKING
Expand Down Expand Up @@ -58,7 +59,12 @@ def render_report(
try:
ret = reporter.report(morfs, outfile=outfile)
if file_to_close is not None:
msgfn(f"Wrote {reporter.report_type} to {output_path}")
if sys.stdout.isatty():
file_path = f"file://{os.path.abspath(output_path)}"
print_path = f"\033]8;;{file_path}\a{output_path}\033]8;;\a"
else:
print_path = output_path
msgfn(f"Wrote {reporter.report_type} to {print_path}")
delete_file = False
return ret
finally:
Expand Down