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

Implement web links and custom link matcher registration #538

Merged
merged 22 commits into from
Feb 17, 2017

Conversation

Tyriar
Copy link
Member

@Tyriar Tyriar commented Feb 10, 2017

Fixes #455

🆕 Web links

This PR adds web links to the terminal which can be clicked to open the URL, a custom handler can be attached which will change the links to use an onclick handler instead.

Terminal.prototype.attachCustomKeydownHandler = function(customKeydownHandler) { ... }

image

🆕 Custom link matchers

The ability for consumers to register custom link matchers has also been added, these are basically the same as web links but can match literally anything the consumer wants.

Terminal.prototype.registerLinkMatcher = function(regex, handler, matchIndex) { ... };
Terminal.prototype.deregisterLinkMatcher = function(matcherId) { ... };

image

Implementation details

  • Web links use the old linkify addon's strictUrlRegex, meaning only http(s) protocol prefixed links will activate
  • Linkification should happen 200ms after a row was last updated, provided no other refresh occurred at which point the timer would be reset. With the default styling of mouse over underline, users likely wouldn't even notice this delay.
  • Link matchers are evaluated in the order in which they are added, starting with the builtin web link handler. This will likely need to change later and support priorities as generally new matchers should be higher priority but the http handler needs to beat out many of them of paths would be incorrectly matched.
  • The web link handler cannot be deregistered.
  • The link matcher API allows the regex match ID to be set, to allow greater flexibility.
  • Testing should be easy after Add PhantomJS test support and CharMeasure tests #535 lands.

@Tyriar Tyriar added this to the 2.4.0 milestone Feb 10, 2017
@Tyriar Tyriar self-assigned this Feb 10, 2017
@Tyriar Tyriar requested a review from parisk February 10, 2017 05:57
This enables consumers to have full control.
Copy link
Contributor

@parisk parisk left a comment

Choose a reason for hiding this comment

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

LGTM and works great for me.

Seems to be resolving #27 also.

@Tyriar
Copy link
Member Author

Tyriar commented Feb 15, 2017

@parisk I'm having second thoughts on how deregister/register works. While currently it's very simple to use, it could be made far more powerful if the link matchers were assigned to actual rows. Consider the following which would be a really cool experience:

  1. Scan for ls line
  2. Register an ls link matcher which will linkify all items in the output
  3. Scan for end of prompt
  4. Deregister ls link matcher

Currently the above will do not linkify anything as the link matcher is immediately deregistered. Before merging this I'm going to look at tighter integration between the linkifier and the rows, so instead of just discarding the link matcher completely on deregister, the rows where it was active would keep a reference to it (which would now live outside Linkifier) and eventually be discarded when all references to it are gone (when all rows that had that link matcher go off the end of the buffer and outside references are dropped).

@parisk
Copy link
Contributor

parisk commented Feb 16, 2017

I think I get it and indeed sounds powerful. Just a clarification question:

How will you register link matchers to lines (e.g. using line number, DOM element, something else)?

Also, will the linkifying happen automatically or the host application has to invoke it manually at will.

@Tyriar
Copy link
Member Author

Tyriar commented Feb 16, 2017

There would need to be another step where when a row is written to it assigns references to the current link handlers on lines. As for where exactly, thinking about it.

@parisk
Copy link
Contributor

parisk commented Feb 17, 2017

Do you plan to implement this in this PR or as an enhancement in a next one?

@Tyriar
Copy link
Member Author

Tyriar commented Feb 17, 2017

In a new one would probably be better provided we don't advertise the API yet as it could change.

@Tyriar
Copy link
Member Author

Tyriar commented Feb 17, 2017

Merging this, created the following follow ups: #549, #550, #551

@Tyriar Tyriar merged commit ae69841 into xtermjs:master Feb 17, 2017
@Tyriar Tyriar deleted the 455_linkify branch February 17, 2017 19:41
@puzrin
Copy link

puzrin commented Feb 28, 2017

@Tyriar I'd suggest to take a look at https://github.com/markdown-it/linkify-it for link pattern search algorythms.

@Tyriar
Copy link
Member Author

Tyriar commented Feb 28, 2017

@puzrin thanks for the link!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support links in the terminal
3 participants