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

Basic link parser for better link detection #2530

Merged
merged 31 commits into from
Feb 8, 2020
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0c5962c
Added support for a basic link parser
jmbockhorst Nov 1, 2019
3e2e4ac
Removed file detection from WebLinkProvider
jmbockhorst Nov 1, 2019
1e877a0
Fix lint errors
jmbockhorst Nov 1, 2019
cf082cc
Fix links when viewport is scrolled
jmbockhorst Nov 1, 2019
ec78fc7
Remove usage of ! operator
jmbockhorst Nov 1, 2019
e57cb8b
Use regex parser for web links
jmbockhorst Nov 1, 2019
fdfadfe
Fixed link caching errors
jmbockhorst Nov 5, 2019
28c43ac
Remove link caching
jmbockhorst Nov 5, 2019
b3d95d2
Merge branch 'master' of https://github.com/xtermjs/xterm.js into lin…
jmbockhorst Nov 5, 2019
ac6c8a5
Support multiline links in the WebLinksAddon
jmbockhorst Nov 6, 2019
b07a6d1
Add test for multiline links
jmbockhorst Nov 6, 2019
f18a6fe
Fixed bug in link detection for wrapped links
jmbockhorst Nov 7, 2019
700c4ac
Rework link parser to use a single cached link and make other request…
jmbockhorst Nov 8, 2019
f93939e
Merge remote-tracking branch 'ups/master' into pr/jmbockhorst/2530
Tyriar Nov 8, 2019
8924aa7
Use onRender() instead of onData() and onScroll()
jmbockhorst Nov 8, 2019
a190634
Only clear link if it was in the range of onRender and fix tests
jmbockhorst Nov 8, 2019
a95b1b4
Merge branch 'master' of https://github.com/xtermjs/xterm.js into lin…
jmbockhorst Feb 4, 2020
e252b4b
Merge branch 'master' into linkParser
Tyriar Feb 7, 2020
a066bbe
:lipstick:
Tyriar Feb 7, 2020
ef071ac
Polish API
Tyriar Feb 7, 2020
c327116
url -> text
Tyriar Feb 7, 2020
b18ded0
Rename tooltip to hover/leave
Tyriar Feb 7, 2020
f4a3125
handle -> activate
Tyriar Feb 7, 2020
0103c68
Start registerLinkProvider tests
Tyriar Feb 7, 2020
7f1f221
Add test for activate
Tyriar Feb 7, 2020
e4875f2
Add test for absense of hover/leave
Tyriar Feb 7, 2020
660cf26
Merge branch 'master' into linkParser
Tyriar Feb 7, 2020
54743ed
Make link matcher API the default for web links addon
Tyriar Feb 8, 2020
a7c2d54
Document link provider argument in web links addon
Tyriar Feb 8, 2020
0e302ba
Mark link matcher API as deprecated
Tyriar Feb 8, 2020
d1d27b5
Remove logs
Tyriar Feb 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' of https://github.com/xtermjs/xterm.js into lin…
…kParser
jmbockhorst committed Feb 4, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
diablodale Dale Phurrough
commit a95b1b4881880a50bd92222a35e1e9ec52f76fd2
33 changes: 15 additions & 18 deletions addons/xterm-addon-web-links/src/WebLinksAddon.api.ts
Original file line number Diff line number Diff line change
@@ -53,24 +53,21 @@ describe('WebLinksAddon', () => {
async function testHostName(hostname: string): Promise<void> {
await openTerminal({ rendererType: 'dom', cols: 40 });
await page.evaluate(`window.term.loadAddon(new window.WebLinksAddon())`);
await page.evaluate(`
window.term.writeln(' http://${hostname} ');
window.term.writeln(' http://${hostname}/a~b#c~d?e~f ');
window.term.writeln(' http://${hostname}/colon:test ');
window.term.writeln(' http://${hostname}/colon:test: ');
window.term.writeln('"http://${hostname}/"');
window.term.writeln('\\'http://${hostname}/\\'');
window.term.writeln('http://${hostname}/subpath/+/id');
window.term.writeln('http://${hostname}/subpath/subpath2/subpath3/subpath4/subpath5/+/id');
`);
assert.equal(await getLinkAtCell(3, 1), `http://${hostname}`);
assert.equal(await getLinkAtCell(3, 2), `http://${hostname}/a~b#c~d?e~f`);
assert.equal(await getLinkAtCell(3, 3), `http://${hostname}/colon:test`);
assert.equal(await getLinkAtCell(3, 4), `http://${hostname}/colon:test`);
assert.equal(await getLinkAtCell(2, 5), `http://${hostname}/`);
assert.equal(await getLinkAtCell(2, 6), `http://${hostname}/`);
assert.equal(await getLinkAtCell(1, 7), `http://${hostname}/subpath/+/id`);
assert.equal(await getLinkAtCell(1, 8) + await getLinkAtCell(1, 9), `http://${hostname}/subpath/subpath2/subpath3/subpath4/subpath5/+/id`);
const data = ` http://${hostname} \\r\\n` +
` http://${hostname}/a~b#c~d?e~f \\r\\n` +
` http://${hostname}/colon:test \\r\\n` +
` http://${hostname}/colon:test: \\r\\n` +
`"http://${hostname}/"\\r\\n` +
`\\'http://${hostname}/\\'\\r\\n` +
`http://${hostname}/subpath/+/id`;
await writeSync(page, data);
await pollForLinkAtCell(3, 1, `http://${hostname}`);
await pollForLinkAtCell(3, 2, `http://${hostname}/a~b#c~d?e~f`);
await pollForLinkAtCell(3, 3, `http://${hostname}/colon:test`);
await pollForLinkAtCell(3, 4, `http://${hostname}/colon:test`);
await pollForLinkAtCell(2, 5, `http://${hostname}/`);
await pollForLinkAtCell(2, 6, `http://${hostname}/`);
await pollForLinkAtCell(1, 7, `http://${hostname}/subpath/+/id`);
}

async function openTerminal(options: ITerminalOptions = {}): Promise<void> {
5 changes: 4 additions & 1 deletion src/Terminal.ts
Original file line number Diff line number Diff line change
@@ -256,7 +256,10 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this.register(this._inputHandler);
}

this.linkifier = this.linkifier || new Linkifier(this._bufferService, this._logService);
if (!this.linkifier) {
this.linkifier = new Linkifier(this._bufferService, this._logService, this.optionsService, this.unicodeService);
}

this.linkifier2 = this.linkifier2 || new Linkifier2(this._bufferService);

if (this.options.windowsMode) {
2 changes: 1 addition & 1 deletion src/TestUtils.test.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import { IDisposable, IMarker, IEvent, ISelectionPosition, ILinkProvider } from
import { Terminal } from './Terminal';
import { AttributeData } from 'common/buffer/AttributeData';
import { IColorManager, IColorSet, ILinkMatcherOptions, ILinkifier, IViewport, ILinkifier2 } from 'browser/Types';
import { IOptionsService } from 'common/services/Services';
import { IOptionsService, IUnicodeService } from 'common/services/Services';
import { EventEmitter } from 'common/EventEmitter';
import { IParams, IFunctionIdentifier } from 'common/parser/Types';
import { ISelectionService } from 'browser/services/Services';
2 changes: 1 addition & 1 deletion src/Types.d.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import { ITerminalOptions as IPublicTerminalOptions, IDisposable, IMarker, ISele
import { ICharset, IAttributeData, CharData, CoreMouseEventType } from 'common/Types';
import { IEvent, IEventEmitter } from 'common/EventEmitter';
import { IColorSet, ILinkifier, ILinkMatcherOptions, IViewport, ILinkifier2 } from 'browser/Types';
import { IOptionsService } from 'common/services/Services';
import { IOptionsService, IUnicodeService } from 'common/services/Services';
import { IBuffer, IBufferSet } from 'common/buffer/Types';
import { IParams, IFunctionIdentifier } from 'common/parser/Types';

12 changes: 6 additions & 6 deletions src/browser/renderer/dom/DomRenderer.ts
Original file line number Diff line number Diff line change
@@ -177,13 +177,13 @@ export class DomRenderer extends Disposable implements IRenderer {
`}`;
// Blink animation
styles +=
`@keyframes blink_box_shadow {` +
`@keyframes blink_box_shadow` + `_` + this._terminalClass + ` {` +
` 50% {` +
` box-shadow: none;` +
` }` +
`}`;
styles +=
`@keyframes blink_block {` +
`@keyframes blink_block` + `_` + this._terminalClass + ` {` +
` 0% {` +
` background-color: ${this._colors.cursor.css};` +
` color: ${this._colors.cursorAccent.css};` +
@@ -200,17 +200,17 @@ export class DomRenderer extends Disposable implements IRenderer {
` outline-offset: -1px;` +
`}` +
`${this._terminalSelector} .${ROW_CONTAINER_CLASS}.${FOCUS_CLASS} .${CURSOR_CLASS}.${CURSOR_BLINK_CLASS}:not(.${CURSOR_STYLE_BLOCK_CLASS}) {` +
` animation: blink_box_shadow 1s step-end infinite;` +
` animation: blink_box_shadow` + `_` + this._terminalClass + ` 1s step-end infinite;` +
`}` +
`${this._terminalSelector} .${ROW_CONTAINER_CLASS}.${FOCUS_CLASS} .${CURSOR_CLASS}.${CURSOR_BLINK_CLASS}.${CURSOR_STYLE_BLOCK_CLASS} {` +
` animation: blink_block 1s step-end infinite;` +
` animation: blink_block` + `_` + this._terminalClass + ` 1s step-end infinite;` +
`}` +
`${this._terminalSelector} .${ROW_CONTAINER_CLASS}.${FOCUS_CLASS} .${CURSOR_CLASS}.${CURSOR_STYLE_BLOCK_CLASS} {` +
` background-color: ${this._colors.cursor.css};` +
` color: ${this._colors.cursorAccent.css};` +
`}` +
`${this._terminalSelector} .${ROW_CONTAINER_CLASS} .${CURSOR_CLASS}.${CURSOR_STYLE_BAR_CLASS} {` +
` box-shadow: 1px 0 0 ${this._colors.cursor.css} inset;` +
` box-shadow: ${this._optionsService.options.cursorWidth}px 0 0 ${this._colors.cursor.css} inset;` +
`}` +
`${this._terminalSelector} .${ROW_CONTAINER_CLASS} .${CURSOR_CLASS}.${CURSOR_STYLE_UNDERLINE_CLASS} {` +
` box-shadow: 0 -1px 0 ${this._colors.cursor.css} inset;` +
@@ -235,7 +235,7 @@ export class DomRenderer extends Disposable implements IRenderer {
`${this._terminalSelector} .${BG_CLASS_PREFIX}${i} { background-color: ${c.css}; }`;
});
styles +=
`${this._terminalSelector} .${FG_CLASS_PREFIX}${INVERTED_DEFAULT_COLOR} { color: ${this._colors.background.css}; }` +
`${this._terminalSelector} .${FG_CLASS_PREFIX}${INVERTED_DEFAULT_COLOR} { color: ${color.opaque(this._colors.background).css}; }` +
`${this._terminalSelector} .${BG_CLASS_PREFIX}${INVERTED_DEFAULT_COLOR} { background-color: ${this._colors.foreground.css}; }`;

this._themeStyleElement.innerHTML = styles;
10 changes: 2 additions & 8 deletions src/public/Terminal.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
* @license MIT
*/

import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, ITerminalAddon, ISelectionPosition, IBuffer as IBufferApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi, IParser, IFunctionIdentifier, ILinkProvider } from 'xterm';
import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, ITerminalAddon, ISelectionPosition, IBuffer as IBufferApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi, IParser, IFunctionIdentifier, ILinkProvider, IUnicodeHandling, IUnicodeVersionProvider } from 'xterm';
import { ITerminal } from '../Types';
import { IBufferLine, ICellData } from 'common/Types';
import { IBuffer } from 'common/buffer/Types';
@@ -231,12 +231,6 @@ class BufferLineApiView implements IBufferLineApi {
}
}

class BufferCellApiView implements IBufferCellApi {
constructor(private _line: IBufferLine, private _x: number) { }
public get char(): string { return this._line.getString(this._x); }
public get width(): number { return this._line.getWidth(this._x); }
}

class ParserApi implements IParser {
constructor(private _core: ITerminal) { }

@@ -267,7 +261,7 @@ class ParserApi implements IParser {
}

class UnicodeApi implements IUnicodeHandling {
constructor(private _core: ITerminal) {}
constructor(private _core: ITerminal) { }

public register(provider: IUnicodeVersionProvider): void {
this._core.unicodeService.register(provider);
You are viewing a condensed version of this merge commit. You can view the full changes here.