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

[terminal] map localhost to external links #6663

Merged
Changes from all commits
Commits
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
18 changes: 9 additions & 9 deletions packages/terminal/src/browser/terminal-linkmatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

import { injectable, inject } from 'inversify';
import { isOSX, } from '@theia/core';
import { WindowService } from '@theia/core/lib/browser/window/window-service';
import { TerminalContribution } from './terminal-contribution';
import { TerminalWidgetImpl } from './terminal-widget-impl';
import { open, OpenerService } from '@theia/core/lib/browser/opener-service';
import URI from '@theia/core/lib/common/uri';

@injectable()
export abstract class AbstractCmdClickTerminalContribution implements TerminalContribution {
Expand Down Expand Up @@ -76,25 +77,24 @@ export abstract class AbstractCmdClickTerminalContribution implements TerminalCo
@injectable()
export class URLMatcher extends AbstractCmdClickTerminalContribution {

@inject(WindowService)
protected readonly windowService: WindowService;
@inject(OpenerService)
protected readonly openerService: OpenerService;

async getRegExp(): Promise<RegExp> {
return /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
}

getHandler(): (event: MouseEvent, uri: string) => void {
return (event: MouseEvent, uri: string) => {
this.windowService.openNewWindow(uri);
};
return (event: MouseEvent, uri: string) =>
open(this.openerService, new URI(uri));
}
}

@injectable()
export class LocalhostMatcher extends AbstractCmdClickTerminalContribution {

@inject(WindowService)
protected readonly windowService: WindowService;
@inject(OpenerService)
protected readonly openerService: OpenerService;

async getRegExp(): Promise<RegExp> {
return /(https?:\/\/)?(localhost|127\.0\.0\.1|0\.0\.0\.0)(:[0-9]{1,5})?([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
Expand All @@ -103,7 +103,7 @@ export class LocalhostMatcher extends AbstractCmdClickTerminalContribution {
getHandler(): (event: MouseEvent, uri: string) => void {
return (event: MouseEvent, matched: string) => {
const uri = matched.startsWith('http') ? matched : `http://${matched}`;
this.windowService.openNewWindow(uri);
open(this.openerService, new URI(uri));
};
}
}