Terminal hyperlinks in help output break easily because the 80 columns print is not aware of escape sequences #613
First Check
Commit to Help
Example Codedef link(uri, label=None, parameters=''):
'''
Found in https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda , windows console and many unix consoles trick to embeed hyperlinks/uri with text
'''
if label is None:
label = uri
# OSC 8 ; params ; URI ST <name> OSC 8 ;; ST
escape_mask = '\033]8;{};{}\033\\{}\033]8;;\033\\'
return escape_mask.format(parameters, uri, label)
import typer
from typing import Optional, List
def test(address: Optional[str] = typer.Option('http://localhost.com', metavar='URL', help=f'URL of {link("https://localhost.com/bigurl-toobiggggggggggggggggg", "the biggest url you have ever seen ever")}.')):
pass
if __name__ == "__main__":
typer.run(test)
#run as 'python3 -m test --help'DescriptionI was wondering it it would be possible to make the print facility of typer when --help is invoked to ignore the length and not break on the middle, of escape sequences so that tricks like the above (placing a url link in the help output of a command for a option) will work. Operating SystemLinux Operating System DetailsNo response Typer Version0.5.0 Python VersionPython 3.10.6 Additional ContextNo response |
Answered by
Danthewaann
Aug 21, 2026
Replies: 1 comment
|
In rich mode ( import typer
URL = "https://example.com/my-docs.md"
app = typer.Typer(
name="my-command",
help="My command help",
epilog=f"More documentation: [link={URL}]{URL}[/link]",
rich_markup_mode="rich"
) |
0 replies
Answer selected by
i30817
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In rich mode (
rich_markup_mode="rich") you can now just use[link=<url>]<display_text>[/link]to create a hyperlink, like so: