summaryrefslogtreecommitdiff
path: root/coverage/misc.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-04-26 21:51:28 -0400
committerNed Batchelder <ned@nedbatchelder.com>2023-04-26 22:01:13 -0400
commit74b1758bb138355d5036631d8c92e7b0871339b2 (patch)
tree680e090e084aea8d76be6f04755663a33cbdecbd /coverage/misc.py
parent3e9205fc3a0c69976e3ca0afb9e43dd5677853b3 (diff)
downloadpython-coveragepy-git-74b1758bb138355d5036631d8c92e7b0871339b2.tar.gz
test: refactor and add a test of terminal link text
Diffstat (limited to 'coverage/misc.py')
-rw-r--r--coverage/misc.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/coverage/misc.py b/coverage/misc.py
index 8cefa12e..061682ee 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -386,3 +386,15 @@ def plural(n: int, thing: str = "", things: str = "") -> str:
return thing
else:
return things or (thing + "s")
+
+
+def stdout_link(text: str, url: str) -> str:
+ """Format text+url as a clickable link for stdout.
+
+ If attached to a terminal, use escape sequences. Otherwise, just return
+ the text.
+ """
+ if sys.stdout.isatty():
+ return f"\033]8;;{url}\a{text}\033]8;;\a"
+ else:
+ return text