Skip to content

Commit 5f31ff9

Browse files
authoredApr 26, 2023
feat: add hyperlink to console output (#1613)
* Add hyperlink to console output * python 3.7 compat version of detecting console tty
1 parent 74f179b commit 5f31ff9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed
 

‎coverage/html.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import re
1414
import shutil
1515
import string # pylint: disable=deprecated-module
16+
import sys
1617

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

494495
index_file = os.path.join(self.directory, "index.html")
495496
write_html(index_file, html)
496-
self.coverage._message(f"Wrote HTML report to {index_file}")
497+
498+
if sys.stdout.isatty():
499+
file_path = f"file://{os.path.abspath(index_file)}"
500+
print_path = f"\033]8;;{file_path}\a{index_file}\033]8;;\a"
501+
else:
502+
print_path = index_file
503+
504+
self.coverage._message(f"Wrote HTML report to {print_path}")
497505

498506
# Write the latest hashes for next time.
499507
self.incr.write()

‎coverage/report.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import annotations
77

8+
import os
89
import sys
910

1011
from typing import Callable, Iterable, Iterator, IO, Optional, Tuple, TYPE_CHECKING
@@ -58,7 +59,12 @@ def render_report(
5859
try:
5960
ret = reporter.report(morfs, outfile=outfile)
6061
if file_to_close is not None:
61-
msgfn(f"Wrote {reporter.report_type} to {output_path}")
62+
if sys.stdout.isatty():
63+
file_path = f"file://{os.path.abspath(output_path)}"
64+
print_path = f"\033]8;;{file_path}\a{output_path}\033]8;;\a"
65+
else:
66+
print_path = output_path
67+
msgfn(f"Wrote {reporter.report_type} to {print_path}")
6268
delete_file = False
6369
return ret
6470
finally:

0 commit comments

Comments
 (0)
Please sign in to comment.