1

I have a ruby terminal script that I would like to print out hyperlinks. I achieve that like so:

puts("\e]8;;https://example.com\aThis is a link\e]8;;\a")

This works perfectly fine in a "normal" terminal (gnome-terminal btw) window.

But I need to run this script within GNU screen, where the escape-sequence simply has no effect. Other sequences (like colors for example) work fine, the hyperlink one (which according to the source might be a gnome-terminal-only thing) doesn't. (screen is running inside gnome-terminal)

How can I get screen to acknowledge my link sequence and display it properly?

3

You can pass through some text to the terminal screen itself runs in by putting it inside an ESC P, ESC \ pair (\033P%s\033\\ in printf format).

So you should bracket inside \eP..\e\\ pairs all the parts of the sequence, except for the text which will appear on the screen ("This is a link"):

printf '\eP\e]8;;https://example.com\a\e\\This is a link\eP\e]8;;\a\e\\\n'
printf '\eP\e]8;;%s\a\e\\%s\eP\e]8;;\a\e\\\n' https://example.com 'This is a link'

Or, from C:

puts("\eP\e]8;;https://example.com\a\e\\This is a link\eP\e]8;;\a\e\\");
printf("\eP\e]8;;%s\a\e\\%s\eP\e]8;;\a\e\\\n", url, title);

Putting the replacement text too inside \eP..\e\\ may result in screen losing track of the cursor position.


This is documented in the GNU screen manual:

ESC P  (A)     Device Control String
               Outputs a string directly to the host
               terminal without interpretation

The "string" should should be terminated with a ST ("string terminator") escape, ie. \e\\ -- thence \eP..\e\\.

| improve this answer | |
  • I might be doing something wrong, but that doesn’t work for me... – Stephen Kitt Mar 27 at 15:43
  • This does not work for me either, neither with printf nor with echo -e nor from the ruby script. It prints This is a link but it's not clickable. Gnome-terminal 3.36.0.1 GNU Screen 4.08.00 – confetti Mar 27 at 15:45
  • @mosvy I know it should work, and I had no doubt you’d tested it. I tried it on Fedora 31 running GNU screen 4.06.02 inside GNOME Terminal 3.34.2, and a remote Debian 10 running GNU screen 4.06.02 inside the same GNOME Terminal. – Stephen Kitt Mar 27 at 15:48
  • With the remote connection, I get ]8;;https://example.comThis is a link; in Fedora, I get an undecorated This is a link. – Stephen Kitt Mar 27 at 15:50
  • 1
    That's because screen will "eat up" the \a which terminates that escape. I will update the answer with a solution which doesn't need that ~/.screenrc mod. – mosvy Mar 27 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.