terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Scenario: Add support for hyperlinks

Open zadjii-msft opened this issue 5 years ago • 46 comments

This is the the megathread for tracking all the remaining work that needs to be done for hyperlink support in Terminal.

"Soon" Timeframe

  • [x] Original issue: #204 -> added in #7251
  • [x] Allow file:// URIs -> added in #7526
  • [ ] #7562 Allow other URI schemes
  • [x] Render hyperlinks differently from regular text in Terminal -> added in #7420
  • [x] Hover underline text that have the same hyperlink ID and display the URI -> added in #7420
  • [x] Display a content dialog box for URIs we cannot parse/schemes we do not support -> added in #7523
  • [x] https://github.com/microsoft/terminal/issues/574 Add support for Terminal to auto-detect hyperlinks -> added in #7691
  • [ ] #7563 Switch the pointer to the 👆 icon when we're hovering a link (in the clickable state, like with ctrl pressed)
  • [ ] VtEngine::_SetHyperlink uses fmt::format to render the hyperlinks, and it should really use _WriteFormattedString
  • [ ] #7564 Hook up hyperlinks to conhost (rendering + clicking)
  • [ ] #7565 Make sure hyperlinks are included in HTML copy
  • [x] #8123 Only underline hyperlinks on hover -> added in #8148
  • [ ] ~Controlling tooltip delay for URLs #8242~
    • Abandoned, platform limitation
  • [x] ~Add a setting to disable auto detection of links (in PR #8239)~
    • Abandoned, we're not sure anyone actually ever wanted this
  • [ ] Links/URLs get offset when certain unicode characters are printed #8709
  • [x] url detection not working with tmux #9117
  • [ ] Keyboard navigation of clickable link #6649
  • [ ] #11901

Backlog

  • [ ] Add a setting to configure the regex used to detect patterns
  • [ ] Allow "hyperlink" matching for arbitrary patterns and adding custom handlers #8849
    • Theoretically, this could supersede #7562
    • Should be self-consistent with #8294
  • [ ] Control the styling of hyperlinks - attributes used for autodetected hyperlinks, and then different attributes for hovered ones #8294
  • [ ] Feature Request: link generation for files + other data types #2671

References

  • This VsCode issue has an enormous set of references to improvements they've made: https://github.com/microsoft/vscode/issues/172084

zadjii-msft avatar Mar 18 '20 21:03 zadjii-msft

Proposed order of attack:

  • Hover tooltip
  • Rendering -- possibly simple rendering w/ a new underline style for me?
  • Take a break, regroup, think about the design for autodetection
  • (possibly work on other things in the meantime)
  • Autodetection

DHowett avatar Aug 20 '20 20:08 DHowett

Hey so hover tooltip might be hard - we can't embed a webview, so doing something like image

Might be especially hard. But we could start with a TeachingTip sytle one for now image

Unless we could somehow pre-render a web page to an image and display that in the tooltip. Or use something like the "social" image from github (though I haven't the damndest clue how that works.)

Maybe we should just start with

Open [web page | file]: 
{url}

in the tooltip

zadjii-msft avatar Aug 21 '20 12:08 zadjii-msft

Yeah i definitely think tooltip and “the link preview from the video” are different workitems that we should tackle separately :)

DHowett avatar Aug 21 '20 15:08 DHowett

If you have to have a "link preview", I'd recommend something really basic based on the page meta data (like the meta title and description, and maybe a favicon and/or og:image). But as cool as this might seem, I don't think it's practical for a hover effect given the delay needed to download and render these things (unless you're pre-rendering the previews, which sounds like a really bad idea).

Which brings me to the main problem. Even if you're only connecting to the site on hover, that still seems inadvisable. When I'm using a terminal I really wouldn't expect it to be making internet connections without my consent. So this feature would definitely have to be optional, and arguably I think should be off by default.

I'm possibly a little biased here, because my internet connection is metered to a certain extent. But even if that weren't the case, would most people be comfortable with their terminal downloading unknown webpages in the background?

j4james avatar Aug 22 '20 23:08 j4james

Yeah, I definitely don't think that "fetch any link I hover over" is something we should ship in core or opt-in by default. It makes for a really compelling video because it shows how modern and flashy we are, but it's too much of a disclosure and safety risk to put right into our project.

DHowett avatar Aug 22 '20 23:08 DHowett

  • Allow mailto: URIs

Would this be RFC conforming 😒 mailto: URL, or 😍 mailto: URL that allows multiple email addresses?

jzabroski avatar Sep 03 '20 19:09 jzabroski

Generally, "whatever type of thing is supported by the registered protocol handler" ;P

DHowett avatar Sep 03 '20 19:09 DHowett

I don't know whether this has been considered already, but when doing a rich-text copy of the terminal buffer the hyperlinks should probably be preserved on paste

jantari avatar Sep 03 '20 20:09 jantari

Thanks @jantari! Just added that to the main scenario body.

DHowett avatar Sep 03 '20 20:09 DHowett

I just built the latest commit, but it can't parse an url, you have to use the escape sequences. Is this use case planned:

echo 'Hello from Windows Terminal: https://github.com/microsoft/terminal/'

And then click on the link and it opens?

giggio avatar Sep 03 '20 21:09 giggio

@giggio er.. image

image

image

DHowett avatar Sep 03 '20 21:09 DHowett

I don't just say these things for fun 😉 (edit: this was intended to be read as "funny", not "wow Dustin's a jerk" (but I get it!))

DHowett avatar Sep 03 '20 21:09 DHowett

I had seen that comment, I was just not sure that this is what it meant, thanks for the clarification, Dustin! And good thing you explained, so I could see it as funny. ;)

So, if I understand correctly, we don't have yet an issue tracking this item (auto-detection) specifically?

giggio avatar Sep 03 '20 22:09 giggio

@giggio There's a lot of discussion about how to do autodetection in the comments on https://github.com/microsoft/terminal/issues/574 :smile: so we're somewhat treating that issue as canonical.

DHowett avatar Sep 03 '20 22:09 DHowett

Question about url detection in 1.5.3142.

Works great in the terminal, but not inside vi. Is the app doing something special to disable this, or a different mode that url detection does not work with? I was really hoping to be able to Ctrl-Click all those documentation links in code comments.

image image

simonratner avatar Nov 11 '20 23:11 simonratner

So, Vim (if that's your vi implementation of choice) enables "mouse mode" -- it lets you select text and navigate the document with your mouse. You can either turn off mouse mode (:set mouse=) or temporarily suppress it by holding down Shift.

(This is also the reason that you cannot select text using the terminal when Vim is running.)

DHowett avatar Nov 11 '20 23:11 DHowett

Thanks for the information, "mouse mode" was not turned on by default for me in:

  • WSL, Ubuntu 20.04 where I tested vim 8.1
  • Windows, where I use neovim v0.5.0-558-g6d1404faf

and links worked OOTB, but I could enable it on either with :set mouse=a and not only did it exhibit the behavior you described but I also learned about mouse-mode today, thanks!

jantari avatar Nov 12 '20 08:11 jantari

There's no solid way to detect the version of the Windows Terminal (and this feature) by an application as of now. One more use case to support #1040 .

One way is to trigger wt -v as wt is available in the Path but the again, it shows up an alert rather than just printing it. (Any reasons it does that?)

abhijit-hota avatar Dec 07 '20 03:12 abhijit-hota

any reasons

About a hundred. The rationale for this spec explains why. https://github.com/microsoft/terminal/blob/dev/duhowett/spec/console-allocation/doc/specs/%237335%20-%20Console%20Allocation%20Policy.md#abstract

DHowett avatar Dec 07 '20 04:12 DHowett

About a hundred. The rationale for this spec explains why. https://github.com/microsoft/terminal/blob/dev/duhowett/spec/console-allocation/doc/specs/%237335%20-%20Console%20Allocation%20Policy.md#abstract

Ah I see. Thanks for the clarification. Waiting for 1040 to get resolved :).

Edit: I don't understand the abstract but I get there are valid reasons.

abhijit-hota avatar Dec 07 '20 04:12 abhijit-hota

I was wondering if there was any plans to support data: URIs? This could be used to embed a (very small) image or just some plain text that would appear, most likely in a popup.

I saw #6747, which suggest support for parsing them is planned for settings.json icons.

There is some info about data: in terminals here: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#gistcomment-2192652

GoodClover avatar Jan 10 '21 15:01 GoodClover

Is there a way to change to modifier key for a link press? I have grown accustomed to using ALT. I couldn't find anything in the documentation, so it would be nice to have this as a keybind setting if it does not exist already.

wongjn avatar Jan 28 '21 23:01 wongjn

I have Windows Terminal 1.5.10271.0 installed, and it looks like Ctrl+Click on http://127.0.0.1:5000 actually already works (which is amazing!) - which release was this made available in? (https://github.com/microsoft/terminal/releases does not seem to contain anything specific about this). Sorry if this is the wrong issue.

image

[1] I know that it is in Windows Terminal Preview v1.5.3142.0 but it doesn't seem to be in the regular Winodws Terminal release notes.

vtjeng avatar Feb 05 '21 19:02 vtjeng

This came out in 1.5!

image

DHowett avatar Feb 05 '21 19:02 DHowett

ftp:// ... I get underlining and a popup "Ctrl+click" tip but can't follow it.

mailto:// ... nothing.

What's the plan? Thanks.

vefatica avatar Mar 11 '21 17:03 vefatica

to be fair, mailto isn’t traditionally followed by // as it does not designate a path. We have issues tracking both “let me customize the URL regex” and “expand protocol support.”

So that’s the plan.

DHowett avatar Mar 11 '21 17:03 DHowett

@vefatica, in v1.7.572.0, TerminalPage::_IsUriSupported allows only http, https, and file. Other URI schemes have been discussed in https://github.com/microsoft/terminal/issues/7562.

KalleOlaviNiemitalo avatar Mar 11 '21 17:03 KalleOlaviNiemitalo

What about ftp://? ... not supported? Yet it gets underlined and a popup tip.

I can't remember way back but in recent decades I've always used mailto://. ShellExecuteEx doesn't mind

vefatica avatar Mar 11 '21 17:03 vefatica

According to https://github.com/microsoft/terminal/pull/7691#discussion_r513595391, ftp: hyperlinks were going to be unblocked "shortly"; but almost five months have passed already. The regex in v1.7.572.0: https://github.com/microsoft/terminal/blob/89c9e6db847ed7f262d1f5a7f972ef004320ff6e/src/cascadia/TerminalCore/Terminal.cpp#L87

KalleOlaviNiemitalo avatar Mar 11 '21 18:03 KalleOlaviNiemitalo