|
|
|
@@ -0,0 +1,41 @@
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
|
|
|
|
* @license MIT
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/// <reference path="../../../typings/xterm.d.ts"/>
|
|
|
|
|
|
|
|
|
|
import { Terminal } from 'xterm';
|
|
|
|
|
|
|
|
|
|
const protocolClause = '(https?:\\/\\/)';
|
|
|
|
|
const domainCharacterSet = '[\\da-z\\.-]+';
|
|
|
|
|
const negatedDomainCharacterSet = '[^\\da-z\\.-]+';
|
|
|
|
|
const domainBodyClause = '(' + domainCharacterSet + ')';
|
|
|
|
|
const tldClause = '([a-z\\.]{2,6})';
|
|
|
|
|
const ipClause = '((\\d{1,3}\\.){3}\\d{1,3})';
|
|
|
|
|
const localHostClause = '(localhost)';
|
|
|
|
|
const portClause = '(:\\d{1,5})';
|
|
|
|
|
const hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + '|' + localHostClause + ')' + portClause + '?';
|
|
|
|
|
const pathClause = '(\\/[\\/\\w\\.\\-%~]*)*';
|
|
|
|
|
const queryStringHashFragmentCharacterSet = '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
|
|
|
|
|
const queryStringClause = '(\\?' + queryStringHashFragmentCharacterSet + ')?';
|
|
|
|
|
const hashFragmentClause = '(#' + queryStringHashFragmentCharacterSet + ')?';
|
|
|
|
|
const negatedPathCharacterSet = '[^\\/\\w\\.\\-%]+';
|
|
|
|
|
const bodyClause = hostClause + pathClause + queryStringClause + hashFragmentClause;
|
|
|
|
|
const start = '(?:^|' + negatedDomainCharacterSet + ')(';
|
|
|
|
|
const end = ')($|' + negatedPathCharacterSet + ')';
|
|
|
|
|
const strictUrlRegex = new RegExp(start + protocolClause + bodyClause + end);
|
|
|
|
|
|
|
|
|
|
function handleLink(event: MouseEvent, uri: string): void {
|
|
|
|
|
window.open(uri, '_blank');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function webLinksInit(term: Terminal): void {
|
|
|
|
|
term.registerLinkMatcher(strictUrlRegex, handleLink, { matchIndex: 1 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function apply(terminalConstructor: typeof Terminal): void {
|
|
|
|
|
(<any>terminalConstructor.prototype).webLinksInit = function (): void {
|
|
|
|
|
webLinksInit(this);
|
|
|
|
|
};
|
|
|
|
|
}
|