diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2023-04-26 21:51:28 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2023-04-26 22:01:13 -0400 |
commit | 74b1758bb138355d5036631d8c92e7b0871339b2 (patch) | |
tree | 680e090e084aea8d76be6f04755663a33cbdecbd /coverage/misc.py | |
parent | 3e9205fc3a0c69976e3ca0afb9e43dd5677853b3 (diff) | |
download | python-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.py | 12 |
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 |