Skip to content

Commit

Permalink
start working on #29816
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed Sep 7, 2021
1 parent 5c1cce4 commit 970a58f
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export const enum TerminalSettingId {
DetectLocale = 'terminal.integrated.detectLocale',
DefaultLocation = 'terminal.integrated.defaultLocation',
GpuAcceleration = 'terminal.integrated.gpuAcceleration',
TerminalTitleSeparator = 'terminal.integrated.spacer',
TerminalTitle = 'terminal.integrated.title',
TerminalDescription = 'terminal.integrated.description',
RightClickBehavior = 'terminal.integrated.rightClickBehavior',
Cwd = 'terminal.integrated.cwd',
ConfirmOnExit = 'terminal.integrated.confirmOnExit',
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ export interface ITerminalInstance {

readonly navigationMode: INavigationMode | undefined;

description: string | undefined;
name: string | undefined;

/**
* Shows the environment information hover if the widget exists.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class TerminalEditorInput extends EditorInput {
}

public override getDescription(): string | undefined {
return this._terminalInstance?.shellLaunchConfig.description;
return this._terminalInstance?.description || this._terminalInstance?.shellLaunchConfig.description;
}

public override toUntyped(): IUntypedEditorInput {
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {

readonly statusList: ITerminalStatusList;
disableLayout: boolean = false;
description: string | undefined = undefined;
name: string | undefined = undefined;
target?: TerminalLocation;
get instanceId(): number { return this._instanceId; }
get resource(): URI { return this._resource; }
Expand Down Expand Up @@ -1750,6 +1752,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
title = title.substring(0, firstSpaceIndex);
}
}
this.name = title;
break;
case TitleEventSource.Api:
// If the title has not been set by the API or the rename command, unregister the handler that
Expand Down
52 changes: 50 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ILabelService } from 'vs/platform/label/common/label';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IKeyMods, IPickOptions, IQuickInputButton, IQuickInputService, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ICreateContributedTerminalProfileOptions, IExtensionTerminalProfile, IShellLaunchConfig, ITerminalLaunchError, ITerminalProfile, ITerminalProfileObject, ITerminalProfileType, ITerminalsLayoutInfo, ITerminalsLayoutInfoById, TerminalLocation, TerminalLocationString, TerminalSettingId, TerminalSettingPrefix } from 'vs/platform/terminal/common/terminal';
import { ICreateContributedTerminalProfileOptions, IExtensionTerminalProfile, IShellLaunchConfig, ITerminalLaunchError, ITerminalProfile, ITerminalProfileObject, ITerminalProfileType, ITerminalsLayoutInfo, ITerminalsLayoutInfoById, TerminalLocation, TerminalLocationString, TerminalSettingId, TerminalSettingPrefix, TitleEventSource } from 'vs/platform/terminal/common/terminal';
import { registerTerminalDefaultProfileConfiguration } from 'vs/platform/terminal/common/terminalPlatformConfiguration';
import { iconForeground } from 'vs/platform/theme/common/colorRegistry';
import { IconDefinition } from 'vs/platform/theme/common/iconRegistry';
Expand All @@ -50,6 +50,7 @@ import { ILifecycleService, ShutdownReason, WillShutdownEvent } from 'vs/workben
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { template } from 'vs/base/common/labels';

export class TerminalService implements ITerminalService {
declare _serviceBrand: undefined;
Expand Down Expand Up @@ -255,6 +256,12 @@ export class TerminalService implements ITerminalService {
e.affectsConfiguration(TerminalSettingPrefix.Profiles + platformKey) ||
e.affectsConfiguration(TerminalSettingId.UseWslProfiles)) {
this._refreshAvailableProfiles();
} else if (
e.affectsConfiguration(TerminalSettingId.TerminalTitle) ||
e.affectsConfiguration(TerminalSettingId.TerminalTitleSeparator)) {
this._updateTitles();
} else if (e.affectsConfiguration(TerminalSettingId.TerminalDescription)) {
this._updateDescriptions();
}
});

Expand Down Expand Up @@ -305,6 +312,45 @@ export class TerminalService implements ITerminalService {

// Create async as the class depends on `this`
timeout(0).then(() => this._instantiationService.createInstance(TerminalEditorStyle, document.head));
this.onDidChangeActiveInstance(async () => {
this._updateTitles();
await this._updateDescriptions();
});
}

private _updateTitles(): void {
for (const terminal of this.instances) {
const title = this._configHelper.config.title;
const separator = this._configHelper.config.spacer;
const newTitle = template(title, {
process: terminal.name,
sequence: 'fsdfsdf',
separator: { label: separator }
});
if (terminal.title !== newTitle) {
terminal.setTitle(newTitle, TitleEventSource.Api);
const pane = this._viewsService.getActiveViewWithId<TerminalViewPane>(TERMINAL_VIEW_ID);
pane?.terminalTabbedView?.rerenderTabs();
}
}
}

private async _updateDescriptions(): Promise<void> {
for (const terminal of this.instances) {
const description = this._configHelper.config.description;
const separator = this._configHelper.config.spacer;
const cwd = await terminal.getCwd();
if (description !== terminal.shellLaunchConfig.description) {
terminal.description = template(description, {
task: terminal.shellLaunchConfig.description === 'Task' ? 'Task' : undefined,
local: !!terminal.isRemote ? 'Local' : undefined,
cwd,
separator: { label: separator }
});
}
const pane = this._viewsService.getActiveViewWithId<TerminalViewPane>(TERMINAL_VIEW_ID);
pane?.terminalTabbedView?.rerenderTabs();
}
}

getOffProcessTerminalService(): IOffProcessTerminalService | undefined {
Expand Down Expand Up @@ -451,7 +497,9 @@ export class TerminalService implements ITerminalService {
// The state must be updated when the terminal is relaunched, otherwise the persistent
// terminal ID will be stale and the process will be leaked.
this.onDidReceiveProcessId(() => this._saveState());
this.onDidChangeInstanceTitle(instance => this._updateTitle(instance));
this.onDidChangeInstanceTitle(instance => {
this._updateTitle(instance);
});
this.onDidChangeInstanceIcon(instance => this._updateIcon(instance));
}

Expand Down
12 changes: 6 additions & 6 deletions src/vs/workbench/contrib/terminal/browser/terminalTabbedView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class TerminalTabbedView extends Disposable {
this._addTabTree();
this._addSashListener();
this._splitView.resizeView(this._tabTreeIndex, this._getLastListWidth());
this._rerenderTabs();
this.rerenderTabs();
}
} else {
if (this._splitView.length === 2 && !this._terminalTabsMouseContextKey.get()) {
Expand Down Expand Up @@ -244,7 +244,7 @@ export class TerminalTabbedView extends Disposable {
width = TerminalTabsListSizes.WideViewMinimumWidth;
this._splitView.resizeView(this._tabTreeIndex, width);
}
this._rerenderTabs();
this.rerenderTabs();
const widthKey = this._panelOrientation === Orientation.VERTICAL ? TerminalStorageKeys.TabsListWidthVertical : TerminalStorageKeys.TabsListWidthHorizontal;
this._storageService.store(widthKey, width, StorageScope.GLOBAL, StorageTarget.USER);
}
Expand Down Expand Up @@ -279,10 +279,10 @@ export class TerminalTabbedView extends Disposable {
onDidChange: () => Disposable.None,
priority: LayoutPriority.Low
}, Sizing.Distribute, this._tabTreeIndex);
this._rerenderTabs();
this.rerenderTabs();
}

private _rerenderTabs() {
rerenderTabs() {
const hasText = this._tabListElement.clientWidth > TerminalTabsListSizes.MidpointViewWidth;
this._tabContainer.classList.toggle('has-text', hasText);
this._terminalIsTabsNarrowContextKey.set(!hasText);
Expand All @@ -294,7 +294,7 @@ export class TerminalTabbedView extends Disposable {
this._sashDisposables = [
this._splitView.sashes[0].onDidStart(e => {
interval = window.setInterval(() => {
this._rerenderTabs();
this.rerenderTabs();
}, 100);
}),
this._splitView.sashes[0].onDidEnd(e => {
Expand All @@ -318,7 +318,7 @@ export class TerminalTabbedView extends Disposable {
if (this._shouldShowTabs()) {
this._splitView.resizeView(this._tabTreeIndex, this._getLastListWidth());
}
this._rerenderTabs();
this.rerenderTabs();
}

private _updateTheme(theme?: IColorTheme): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class TerminalTabsRenderer implements IListRenderer<ITerminalInstance, ITerminal
template.label.setResource({
resource: instance.resource,
name: label,
description: hasText ? instance.shellLaunchConfig.description : undefined
description: hasText ? instance.shellLaunchConfig.description ? instance.shellLaunchConfig.description : instance.description : undefined
}, {
fileDecorations: {
colors: true,
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ export interface ITerminalConfiguration {
bellDuration: number;
defaultLocation: TerminalLocationString;
customGlyphs: boolean;
title: string;
description: string;
spacer: string;
}

export const DEFAULT_LOCAL_ECHO_EXCLUDE: ReadonlyArray<string> = ['vim', 'vi', 'nano', 'tmux'];
Expand Down
36 changes: 36 additions & 0 deletions src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ import { DEFAULT_LETTER_SPACING, DEFAULT_LINE_HEIGHT, TerminalCursorStyle, DEFAU
import { TerminalLocationString, TerminalSettingId } from 'vs/platform/terminal/common/terminal';
import { isMacintosh, isWindows } from 'vs/base/common/platform';
import { Registry } from 'vs/platform/registry/common/platform';
let terminalTitleDescription = localize('terminalTitle', "Controls the terminal title. Variables are substituted based on the context:");
terminalTitleDescription += '\n- ' + [
localize('process', "`\${process}`: the name of the terminal process"),
localize('sequence', "`\${sequence}`: a sequence"),
localize('separator', "`\${separator}`: a conditional separator (\" - \") that only shows when surrounded by variables with values or static text.")
].join('\n- '); // intentionally concatenated to not produce a string that is too long for translations

let terminalDescriptionDescription = localize('terminalDescription', "Controls the terminal description, which appears to the right of the title. Variables are substituted based on the context:");
terminalDescriptionDescription += '\n- ' + [
localize('task', "`\${process}`: indicates this terminal is associated with a task"),

This comment has been minimized.

Copy link
@Tyriar

Tyriar Sep 7, 2021

Member

typo: ${task}

localize('local', "`\${local}`: indicates a local terminal in a remote workspace"),
localize('cwd', "`\${cwd}`: the terminal's current working directory"),
localize('separator', "`\${separator}`: a conditional separator (\" - \") that only shows when surrounded by variables with values or static text.")
].join('\n- '); // intentionally concatenated to not produce a string that is too long for translations

const terminalConfiguration: IConfigurationNode = {
id: 'terminal',
Expand Down Expand Up @@ -247,6 +261,28 @@ const terminalConfiguration: IConfigurationNode = {
default: 'auto',
description: localize('terminal.integrated.gpuAcceleration', "Controls whether the terminal will leverage the GPU to do its rendering.")
},
[TerminalSettingId.TerminalTitleSeparator]: {
'type': 'string',
'default': isMacintosh ? ' — ' : ' - ',
'markdownDescription': localize("terminal.integrated.spacer", "Separator used by `terminal.integrated.title` and `terminal.integrated.description`.")
},
[TerminalSettingId.TerminalTitle]: {
'type': 'string',
'default': (() => {
const base = '${process}';

This comment has been minimized.

Copy link
@Tyriar

Tyriar Sep 7, 2021

Member

Can this just be default: '${process}'?

return base;
})(),
'markdownDescription': terminalTitleDescription
},
[TerminalSettingId.TerminalDescription]: {
'type': 'string',
'default': (() => {
const base = '${task}${separator}${local}${separator}${cwd}';
return base;
})(),
'markdownDescription': terminalDescriptionDescription

},
[TerminalSettingId.RightClickBehavior]: {
type: 'string',
enum: ['default', 'copyPaste', 'paste', 'selectWord'],
Expand Down

0 comments on commit 970a58f

Please sign in to comment.