Add a revive setting, refine when it's triggered

This commit is contained in:
Daniel Imms
2021-09-16 09:25:29 -07:00
parent 01d1dcbb00
commit db3d7d5e4e
4 changed files with 29 additions and 7 deletions
@@ -92,6 +92,7 @@ export const enum TerminalSettingId {
LocalEchoExcludePrograms = 'terminal.integrated.localEchoExcludePrograms',
LocalEchoStyle = 'terminal.integrated.localEchoStyle',
EnablePersistentSessions = 'terminal.integrated.enablePersistentSessions',
PersistentSessionReviveProcess = 'terminal.integrated.persistentSessionReviveProcess',
CustomGlyphs = 'terminal.integrated.customGlyphs',
PersistentSessionScrollback = 'terminal.integrated.persistentSessionScrollback',
PersistentSessionExperimentalSerializer = 'terminal.integrated.persistentSessionExperimentalSerializer',
@@ -555,12 +555,10 @@ export class TerminalService implements ITerminalService {
return false;
}
// Persist terminal _buffer state_
if (this._configHelper.config.enablePersistentSessions && reason !== ShutdownReason.RELOAD) {
console.log('persist buffer, reason: ' + reason);
// TODO: Fine tune which reasons are supported - what is LOAD?
// TODO: This is called once per workspace?
// TODO: Either do this or confirm dialog?
// Persist terminal _buffer state_, note that even if this happens the dirty terminal prompt
// still shows as that cannot be revived
const shouldReviveProcesses = this._shouldReviveProcesses(reason);
if (shouldReviveProcesses) {
await this._localTerminalService?.persistTerminalState();
}
@@ -581,6 +579,17 @@ export class TerminalService implements ITerminalService {
return false;
}
private _shouldReviveProcesses(reason: ShutdownReason): boolean {
if (!this._configHelper.config.enablePersistentSessions) {
return false;
}
switch (this.configHelper.config.persistentSessionReviveProcess) {
case 'onExit': return reason === ShutdownReason.LOAD || reason === ShutdownReason.QUIT;
case 'onExitOrWindowClose': return reason !== ShutdownReason.RELOAD;
default: return false;
}
}
private async _onBeforeShutdownAsync(reason: ShutdownReason): Promise<boolean> {
// veto if configured to show confirmation and the user chose not to exit
const veto = await this._showTerminalCloseConfirmation();
@@ -607,7 +616,7 @@ export class TerminalService implements ITerminalService {
}
// Clear terminal layout info only when not persisting
if (!persistTerminalState) {
if (!this._shouldReviveProcesses(e.reason)) {
this._localTerminalService?.setTerminalLayoutInfo(undefined);
}
}
@@ -209,6 +209,7 @@ export interface ITerminalConfiguration {
bellDuration: number;
defaultLocation: TerminalLocationString;
customGlyphs: boolean;
persistentSessionReviveProcess: 'onExit' | 'onExitOrWindowClose' | 'never';
}
export const DEFAULT_LOCAL_ECHO_EXCLUDE: ReadonlyArray<string> = ['vim', 'vi', 'nano', 'tmux'];
@@ -483,6 +483,17 @@ const terminalConfiguration: IConfigurationNode = {
type: 'boolean',
default: true
},
[TerminalSettingId.PersistentSessionReviveProcess]: {
description: localize('terminal.integrated.persistentSessionReviveProcess', "When the terminal process must be shutdown (eg. on window or application close), this determines when the previous terminal session contents should be restored and processes recreated when the workspace is next opened."),
type: 'string',
enum: ['onExit', 'onExitAndWindowClose', 'never'],
markdownEnumDescriptions: [
localize('terminal.integrated.persistentSessionReviveProcess.onExit', "Revive the processes after the last window is closed on Windows/Linux or when the `workbench.action.quit` command is triggered (command palette, keybinding, menu)."),
localize('terminal.integrated.persistentSessionReviveProcess.onExitAndWindowClose', "Revive the processes after the last window is closed on Windows/Linux or when the `workbench.action.quit` command is triggered (command palette, keybinding, menu), or when the window is closed."),
localize('terminal.integrated.persistentSessionReviveProcess.never', "Never restore the terminal buffers or recreate the process.")
],
default: 'onExit'
},
[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 with the DOM renderer"),
type: 'boolean',