Real working hyperlinks in the terminal with Rich
Since releasing Rich 1.0.0 I've discovered that terminals support hyperlinks. And I don't mean the helpful highlighting of URLs that most terminals do, I mean actual HTML-like hyperlinks that launch a browser.
This was news to me, as I've never seen this feature in the wild. I just had to add it to Rich. The easiest way to output hyperlinks is via console markup. Here's a simple example:
>>> from rich import print
>>> print("Visit my [link=https://www.willmcgugan.com]blog[/link]!")
This will output the text "Visit my blog!" in the terminal where the word "blog" is a clickable link that opens the browser.
This is a relatively new (2017) addition to the spec, so it isn't supported on all terminal apps. If your terminal doesn't support hyperlinks then the link won't be clickable, but you will see the text as normal.
I've also added this to the the markdown renderer, which will now render working links. This is best demonstrated in a video:
i tried this
from rich import print print("Visit my [link=https://www.willmcgugan.com]blog[/link]!")
but it is not workingDid you see the text?
If it wasn't clickable it may be because your terminal doesn't support links.
Is there any way to know if the terminal supports links or not?
yes, it is not clickable in my case also do you have any solution
Once https://github.com/xtermjs/xterm.js/pull/4005 with get merged and release we should expect to also see hyperlinks working in vscode own terminal. Until then, feel free to enjoy them in other terminals. The good part is that when terminal does not support them, they just see plain text that cannot be clicked, no garbage on the screen.
The rich library continues to impress.