Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn the Location: into a terminal hyperlink #7963

Merged
merged 1 commit into from Mar 12, 2022
Merged

Conversation

dfandrich
Copy link
Contributor

I just learned about a new capability that terminals have gained in the last
few years, namely the ability to create clickable hyperlinks on the terminal
with arbitrary text. Many terminals already turn URLs on screen into clickable
links but there are times when curl could supply links that aren't displayed on
screen.

This PR adds the ability for curl to create hyperlinks for Location: redirects.
There is not enough information for a terminal to do this automatically for
relative URLs, but curl has enough information to do it. This is enabled when
--styled-output is turned on and a Location: header is displayed.

There are probably other cases when curl could enhance the output with links
like this, so this is mostly a proof of concept to see how easy and useful it
is. It turns out that this marginal feature takes a surprising amount of code
to accomplish due to CURLINFO_REDIRECT_URL being unavailable. I won't take it
personally if the end result is rejection this PR for a too-low
price/performance ratio.

@dfandrich
Copy link
Contributor Author

Here is an example using vte.
hyperlink

Copy link
Member

@bagder bagder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! I'm just a tad bit worried what this might do in terminals without support?

src/tool_cb_hdr.c Outdated Show resolved Hide resolved
@dfandrich
Copy link
Contributor Author

I tried this on five different terminal that do not support OSC 8 hyperlinks, or at least don't do anything with them (Konsole, xterm, eterm, screen, Linux console), and all of them ignored the hyperlink and displayed the text as before. It's been a while since I've looked at the ANSI spec, but I'm guessing it's using some feature of the escape sequences that's designed to be ignored by terminals that don't know about this feature.

}
else
fwrite(&value[1], cb - namelen - 1, 1, outs->stream);
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rather put this whole block into its own function to make it easier to deal with when glancing the code.

@dfandrich
Copy link
Contributor Author

I've moved the new code into a new function, as requested, and fixed the memory cleanup to use the right curl_free function. I think it's ready to be submitted now.

@ghost
Copy link

ghost commented Mar 10, 2022 via email

This turns even relative URLs into clickable hyperlinks in a supported
terminal when --styled-output is enabled. Many terminals already turn
URLs into clickable links but there is not enough information in a
relative URL to do this automatically otherwise.
@dfandrich
Copy link
Contributor Author

There was a compiler warning in the non-enabled case that broke some builds. I've fixed that now.

@dfandrich dfandrich merged commit 3055c4c into master Mar 12, 2022
@dfandrich dfandrich deleted the dfandrich/hyperlink branch March 12, 2022 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants