tty-link
tty-link copied to clipboard
Does not detect hyperlink support in other terminals
Describe the problem
Alacritty, Kitty, and KDE's Konsole all support the hyperlink escape code. It's not just iTerm & VTE based terminals.
Steps to reproduce the problem
puts TTY::Link("foo", "https://google.com")
Actual behaviour
To print out the hyperlink.
Expected behaviour
Fallback output was printed instead.
Describe your environment
- OS version: Arch Linux
- Ruby version: 3.2.2
- TTY::Link version: 0.1.1
Thanks for submitting this issue. 🙏
It's not just iTerm & VTE based terminals.
At the time this gem was created this was the case. These were the first terminals to support hyperlinks. The world has changed since. Alacritty has added support only recently(around 2022).
Therefore, I disagree that this is a 'bug'. More of a feature request. I'm sure you can appreciate that there are more terminals adding hyperlinks support and more terminals appearing all the time. This is in a way an 'impossible' task to create detection that works for every terminal including the ones that don't even exist yet. However, we can certainly try to support the most common ones.
I'd welcome help here. It can be in many forms. Either a PR that implements support for a given terminal. Alternatively, information on how to detect the terminal type from ENV and whether there is a version requirement. For example, use this name from the TERM variable and apply it to any version higher than 3.0 using X_VERSION variable. Ideally, this would be tested by installing a given terminal and verifying that detection works.
Further, we could add a configuration option to the link_to to allow overriding automatic detection. For example, it could take one of always|auto|never:
TTY::Link.link_to("ttytoolkit.org", "https://ttytoolkit.org", hyperlink: :always)
Similarly, provide an environment variable to allow configuration for a tool that uses tty-link:
TTY_LINK_HYPERLINK=never
The official mechanism would be to query the terminfo database for the capability, using something like this library. I'm not certain what the hyperlink capability is called.
In the mean time, adding an parameter would be a good stop-gap.
The official mechanism would be to query the terminfo database for the capability
This sentiment is not universally appreciated. See the comments from the kitty terminal issue in regards to hyperlinks.
termcap/terminfo is an awful solution because it means you have to have the terminfo files on remote servers as well when using SSH. Not to mention that the maintainers of terminfo have gone permanently to sleep.
Further, there are more direct downsides to using terminfo:
- The ruby-terminfo uses C extensions that no longer compile on modern Ruby. I tried to install it on 3.2. There are no modern alternatives and I won't be investing time in writing my own.
- The info added to terminfo doesn't seem to contain anything related to hyperlinks support capability as far as I can tell.
- No every terminal emulator adds entries to terminfo database. For example, very popular hyper terminal doesn't do it.
It feels rather heavy-handed solution for such a small library to employ. I'd rather rely on environment variables and do the best-approximated feature detection possible. I don't want perfect accuracy, if I can detect let's say alacritty terminal and cannot get its version, I'm fine assuming it supports hyperlinks for all versions.
Would you have time to provide help with identifying terminals with hyperlinks support and their env variables?