From 74b1758bb138355d5036631d8c92e7b0871339b2 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 26 Apr 2023 21:51:28 -0400 Subject: test: refactor and add a test of terminal link text --- coverage/misc.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'coverage/misc.py') 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 -- cgit v1.2.1