Skip to content

Commit

Permalink
Improve shell integration welcome hover
Browse files Browse the repository at this point in the history
Part of #141483
  • Loading branch information
Tyriar committed Feb 4, 2022
1 parent 19034bc commit fd0b5d8
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ export const enum TerminalSettingId {
ShowLinkHover = 'terminal.integrated.showLinkHover',
IgnoreProcessNames = 'terminal.integrated.ignoreProcessNames',
AutoReplies = 'terminal.integrated.autoReplies',
EnableShellIntegration = 'terminal.integrated.enableShellIntegration'
EnableShellIntegration = 'terminal.integrated.enableShellIntegration',
ShowShellIntegrationWelcome = 'terminal.integrated.showShellIntegrationWelcome'
}

export enum WindowsShellType {
Expand Down
20 changes: 13 additions & 7 deletions src/vs/workbench/contrib/terminal/browser/links/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { IBufferLine, IBufferRange, Terminal } from 'xterm';
import { URI } from 'vs/base/common/uri';
import { IHoverAction } from 'vs/workbench/services/hover/browser/hover';

/**
* A link detector can search for and return links within the xterm.js buffer. A single link
Expand Down Expand Up @@ -34,6 +35,16 @@ export interface ITerminalSimpleLink {
*/
text: string;

/**
* The buffer range of the link.
*/
readonly bufferRange: IBufferRange;

/**
* The type of link, which determines how it is handled when activated.
*/
readonly type: TerminalLinkType;

/**
* The URI of the link if it has been resolved.
*/
Expand All @@ -45,14 +56,9 @@ export interface ITerminalSimpleLink {
label?: string;

/**
* The buffer range of the link.
*/
readonly bufferRange: IBufferRange;

/**
* The type of link, which determines how it is handled when activated.
* An optional set of actions to show in the hover's status bar.
*/
readonly type: TerminalLinkType;
actions?: IHoverAction[];
}

export type TerminalLinkType = TerminalBuiltinLinkType | ITerminalExternalLinkType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isMacintosh } from 'vs/base/common/platform';
import { localize } from 'vs/nls';
import { Emitter, Event } from 'vs/base/common/event';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IHoverAction } from 'vs/workbench/services/hover/browser/hover';

export const OPEN_FILE_LABEL = localize('openFile', 'Open file in editor');
export const FOLDER_IN_WORKSPACE_LABEL = localize('focusFolder', 'Focus folder in explorer');
Expand All @@ -31,6 +32,7 @@ export class TerminalLink extends DisposableStore implements ILink {
private readonly _xterm: Terminal,
readonly range: IBufferRange,
readonly text: string,
readonly actions: IHoverAction[] | undefined,
private readonly _viewportY: number,
private readonly _activateCallback: (event: MouseEvent | undefined, uri: string) => Promise<void>,
private readonly _tooltipCallback: (link: TerminalLink, viewportRange: IViewportRange, modifierDownCallback?: () => void, modifierUpCallback?: () => void) => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class TerminalLinkDetectorAdapter extends Disposable implements ILinkProv
this._detector.xterm,
l.bufferRange,
l.text,
l.actions,
this._detector.xterm.buffer.active.viewportY,
activateCallback,
(link, viewportRange, modifierDownCallback, modifierUpCallback) => this._onDidShowHover.fire({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/wid
import { IXtermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private';
import { ITerminalCapabilityStore, TerminalCapability } from 'vs/workbench/contrib/terminal/common/capabilities/capabilities';
import { ITerminalConfiguration, ITerminalProcessManager, TERMINAL_CONFIG_SECTION } from 'vs/workbench/contrib/terminal/common/terminal';
import { IHoverAction } from 'vs/workbench/services/hover/browser/hover';
import type { ILink, ILinkProvider, IViewportRange, Terminal } from 'xterm';

export type XtermLinkMatcherHandler = (event: MouseEvent | undefined, link: string) => Promise<void>;
Expand Down Expand Up @@ -211,17 +212,18 @@ export class TerminalLinkManager extends DisposableStore {
terminalDimensions,
modifierDownCallback,
modifierUpCallback
}, this._getLinkHoverString(link.text, link.label), (text) => link.activate(undefined, text), link);
}, this._getLinkHoverString(link.text, link.label), link.actions, (text) => link.activate(undefined, text), link);
}

private _showHover(
targetOptions: ILinkHoverTargetOptions,
text: IMarkdownString,
actions: IHoverAction[] | undefined,
linkHandler: (url: string) => void,
link?: TerminalLink
) {
if (this._widgetManager) {
const widget = this._instantiationService.createInstance(TerminalHover, targetOptions, text, linkHandler);
const widget = this._instantiationService.createInstance(TerminalHover, targetOptions, text, actions, linkHandler);
const attached = this._widgetManager.attachWidget(widget);
if (attached) {
link?.onInvalidated(() => attached.dispose());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TerminalSettingId } from 'vs/platform/terminal/common/terminal';
import { ITerminalSimpleLink, ITerminalLinkDetector, TerminalBuiltinLinkType } from 'vs/workbench/contrib/terminal/browser/links/links';
import { terminalStrings } from 'vs/workbench/contrib/terminal/common/terminalStrings';
import { IBufferCell, IBufferLine, Terminal } from 'xterm';

const linkText = 'Shell integration activated!';
Expand All @@ -15,7 +19,8 @@ export class TerminalShellIntegrationLinkDetector implements ITerminalLinkDetect
static id = 'shellintegration';

constructor(
readonly xterm: Terminal
readonly xterm: Terminal,
@IConfigurationService private readonly _configurationService: IConfigurationService
) {
}

Expand All @@ -24,14 +29,20 @@ export class TerminalShellIntegrationLinkDetector implements ITerminalLinkDetect
return [{
text: linkText,
type: TerminalBuiltinLinkType.Url,
label: localize('learn', 'Learn about shell integration'),
uri: URI.from({
scheme: Schemas.https,
path: 'aka.ms/vscode-shell-integration'
}),
bufferRange: {
start: { x: 1, y: startLine + 1 },
end: { x: linkText.length % this.xterm.cols, y: startLine + Math.floor(linkText.length / this.xterm.cols) + 1 }
}
},
actions: [{
label: terminalStrings.doNotShowAgain,
commandId: '',
run: () => this._hideMessage()
}]
}];
}

Expand All @@ -48,4 +59,8 @@ export class TerminalShellIntegrationLinkDetector implements ITerminalLinkDetect
}
return true;
}

private async _hideMessage() {
await this._configurationService.updateValue(TerminalSettingId.ShowShellIntegrationWelcome, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Widget } from 'vs/base/browser/ui/widget';
import { ITerminalWidget } from 'vs/workbench/contrib/terminal/browser/widgets/widgets';
import * as dom from 'vs/base/browser/dom';
import type { IViewportRange } from 'xterm';
import { IHoverTarget, IHoverService } from 'vs/workbench/services/hover/browser/hover';
import { IHoverTarget, IHoverService, IHoverAction } from 'vs/workbench/services/hover/browser/hover';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorHoverHighlight } from 'vs/platform/theme/common/colorRegistry';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand All @@ -31,6 +31,7 @@ export class TerminalHover extends Disposable implements ITerminalWidget {
constructor(
private readonly _targetOptions: ILinkHoverTargetOptions,
private readonly _text: IMarkdownString,
private readonly _actions: IHoverAction[] | undefined,
private readonly _linkHandler: (url: string) => any,
@IHoverService private readonly _hoverService: IHoverService,
@IConfigurationService private readonly _configurationService: IConfigurationService
Expand All @@ -51,6 +52,7 @@ export class TerminalHover extends Disposable implements ITerminalWidget {
const hover = this._hoverService.showHover({
target,
content: this._text,
actions: this._actions,
linkHandler: this._linkHandler,
// .xterm-hover lets xterm know that the hover is part of a link
additionalClasses: ['xterm-hover']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,12 @@ const terminalConfiguration: IConfigurationNode = {
type: 'boolean',
default: false
},
[TerminalSettingId.ShowShellIntegrationWelcome]: {
restricted: true,
markdownDescription: localize('terminal.integrated.showShellIntegrationWelcome', "Whether to show the shell integration activated welcome message in the terminal when the feature is enabled."),
type: 'boolean',
default: true
},
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function formatMessageForTerminal(message: string, excludeLeadingNewLine:
*/
export const terminalStrings = {
terminal: localize('terminal', "Terminal"),
doNotShowAgain: localize('doNotShowAgain', 'Do Not Show Again'),
focus: {
value: localize('workbench.action.terminal.focus', "Focus Terminal"),
original: 'Focus Terminal'
Expand Down

0 comments on commit fd0b5d8

Please sign in to comment.