From 6b8fd6a5290a44ee03ae5eaec052e76d831b4975 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 28 Jul 2023 17:17:25 -0700 Subject: [PATCH] Add hideOnStartup terminal setting Fixes #39137 --- src/vs/platform/terminal/common/terminal.ts | 1 + .../contrib/terminal/browser/terminalView.ts | 31 +++++++++++++++++-- .../terminal/common/terminalConfiguration.ts | 11 +++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index 1f019a69053c6..874aef7bb3802 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -98,6 +98,7 @@ export const enum TerminalSettingId { LocalEchoStyle = 'terminal.integrated.localEchoStyle', EnablePersistentSessions = 'terminal.integrated.enablePersistentSessions', PersistentSessionReviveProcess = 'terminal.integrated.persistentSessionReviveProcess', + HideOnStartup = 'terminal.integrated.hideOnStartup', CustomGlyphs = 'terminal.integrated.customGlyphs', PersistentSessionScrollback = 'terminal.integrated.persistentSessionScrollback', InheritEnv = 'terminal.integrated.inheritEnv', diff --git a/src/vs/workbench/contrib/terminal/browser/terminalView.ts b/src/vs/workbench/contrib/terminal/browser/terminalView.ts index 1f70e8d088a19..c1a38a3f014f7 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalView.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalView.ts @@ -55,6 +55,7 @@ export class TerminalViewPane extends ViewPane { private _terminalTabbedView?: TerminalTabbedView; get terminalTabbedView(): TerminalTabbedView | undefined { return this._terminalTabbedView; } private _isWelcomeShowing: boolean = false; + private _isInitialized: boolean = false; private _newDropdown: DropdownWithPrimaryActionViewItem | undefined; private readonly _dropdownMenu: IMenu; private readonly _singleTabMenu: IMenu; @@ -131,15 +132,41 @@ export class TerminalViewPane extends ViewPane { private _initializeTerminal(checkRestoredTerminals: boolean) { if (this.isBodyVisible() && this._terminalService.isProcessSupportRegistered && this._terminalService.connectionState === TerminalConnectionState.Connected) { + const wasInitialized = this._isInitialized; + this._isInitialized = true; + + let hideOnStartup: 'never' | 'whenEmpty' | 'always' = 'never'; + if (!wasInitialized) { + hideOnStartup = this._configurationService.getValue(TerminalSettingId.HideOnStartup); + if (hideOnStartup === 'always') { + this._terminalGroupService.hidePanel(); + } + } + let shouldCreate = this._terminalGroupService.groups.length === 0; // When triggered just after reconnection, also check there are no groups that could be // getting restored currently if (checkRestoredTerminals) { shouldCreate &&= this._terminalService.restoredGroupCount === 0; } - if (shouldCreate) { - this._terminalService.createTerminal({ location: TerminalLocation.Panel }); + if (!shouldCreate) { + return; } + if (!wasInitialized) { + switch (hideOnStartup) { + case 'never': + this._terminalService.createTerminal({ location: TerminalLocation.Panel }); + break; + case 'whenEmpty': + if (this._terminalService.restoredGroupCount === 0) { + this._terminalGroupService.hidePanel(); + } + break; + } + return; + } + + this._terminalService.createTerminal({ location: TerminalLocation.Panel }); } } diff --git a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts index e7f30f75609e0..1ca34b88c2e3b 100644 --- a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts +++ b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts @@ -529,6 +529,17 @@ const terminalConfiguration: IConfigurationNode = { ], default: 'onExit' }, + [TerminalSettingId.HideOnStartup]: { + description: localize('terminal.integrated.hideOnStartup', "Whether to hide the terminal view on startup, avoiding creating a terminal when there are no persistent sessions."), + type: 'string', + enum: ['never', 'whenEmpty', 'always'], + markdownEnumDescriptions: [ + localize('hideOnStartup.never', "Never hide the terminal view on startup."), + localize('hideOnStartup.whenEmpty', "Only hide the terminal when there are no persistent sessions restored."), + localize('hideOnStartup.always', "Always hide the terminal, even when there are persistent sessions restored.") + ], + default: 'never' + }, [TerminalSettingId.CustomGlyphs]: { description: localize('terminal.integrated.customGlyphs', "Whether to draw custom glyphs for block element and box drawing characters instead of using the font, which typically yields better rendering with continuous lines. Note that this doesn't work when {0} is disabled.", `\`#${TerminalSettingId.GpuAcceleration}#\``), type: 'boolean',