onDidClose

abstract var onDidClose: Event<JsInt?>?(source)

An event that when fired will signal that the pty is closed and dispose of the terminal.

Events fired before Pseudoterminal.open is called will be be ignored.

A number can be used to provide an exit code for the terminal. Exit codes must be positive and a non-zero exit codes signals failure which shows a notification for a regular terminal and allows dependent tasks to proceed when used with the CustomExecution API.

Example: Exit the terminal when "y" is pressed, otherwise show a notification.

const writeEmitter = new vscode.EventEmitter<string>();
const closeEmitter = new vscode.EventEmitter<void>();
const pty: vscode.Pseudoterminal = {
onDidWrite: writeEmitter.event,
onDidClose: closeEmitter.event,
open: () => writeEmitter.fire('Press y to exit successfully'),
close: () => {},
handleInput: data => {
if (data !== 'y') {
vscode.window.showInformationMessage('Something went wrong');
}
closeEmitter.fire();
}
};
const terminal = vscode.window.createTerminal({ name: 'Exit example', pty });
terminal.show(true);

Online Documentation