Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/webview/openshift-terminal/openShiftTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class OpenShiftTerminal {
private _file: string;
private _args: string | string[];
private _options;
private _name: string;

private _sendTerminalData: (data: string) => void;
private _sendExitMessage: () => void;
Expand Down Expand Up @@ -133,6 +134,7 @@ class OpenShiftTerminal {
this._file = file;
this._args = args;
this._options = options;
this._name = options.name;

this._disposables = [];
this._headlessTerm = new Terminal({ allowProposedApi: true });
Expand Down Expand Up @@ -195,6 +197,15 @@ class OpenShiftTerminal {
this._ptyExited = true;
}

/**
* Returns the name of this terminal.
*
* @returns the name of this terminal
*/
public get name() {
return this._name;
}

/**
* Returns the unique identifier of this terminal.
*
Expand Down Expand Up @@ -321,6 +332,14 @@ class OpenShiftTerminal {
public stopRendering(): void {
this._terminalRendering = false;
}

/**
* Close this terminal tab, force killing the process if it's still running.
*/
public closeTab(): void {
this.forceKill();
this._sendExitMessage();
}
}

/**
Expand Down Expand Up @@ -549,6 +568,14 @@ export class OpenShiftTerminalManager implements WebviewViewProvider {
throw new Error(msg);
}

// try to clean up an existing exited terminal in place of this one
for (const existingTerm of this.openShiftTerminals.values()) {
if (!existingTerm.isPtyLive && existingTerm.name === name) {
existingTerm.closeTab();
break;
}
}

const newTermUUID = randomUUID();

// create the object that manages the headless terminal and the pty.
Expand Down