Skip to content

Commit b28ef38

Browse files
committed
If a command is rerun after exiting, close the old tab
Not quite the same as recycling the tab, but it has a much simpler implementation. Closes #3138 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 7865e17 commit b28ef38

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/webview/openshift-terminal/openShiftTerminal.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class OpenShiftTerminal {
7474
private _file: string;
7575
private _args: string | string[];
7676
private _options;
77+
private _name: string;
7778

7879
private _sendTerminalData: (data: string) => void;
7980
private _sendExitMessage: () => void;
@@ -133,6 +134,7 @@ class OpenShiftTerminal {
133134
this._file = file;
134135
this._args = args;
135136
this._options = options;
137+
this._name = options.name;
136138

137139
this._disposables = [];
138140
this._headlessTerm = new Terminal({ allowProposedApi: true });
@@ -195,6 +197,15 @@ class OpenShiftTerminal {
195197
this._ptyExited = true;
196198
}
197199

200+
/**
201+
* Returns the name of this terminal.
202+
*
203+
* @returns the name of this terminal
204+
*/
205+
public get name() {
206+
return this._name;
207+
}
208+
198209
/**
199210
* Returns the unique identifier of this terminal.
200211
*
@@ -321,6 +332,18 @@ class OpenShiftTerminal {
321332
public stopRendering(): void {
322333
this._terminalRendering = false;
323334
}
335+
336+
/**
337+
* Close this terminal tab, assuming the process it's running exited.
338+
*
339+
* @throws if the process is still running
340+
*/
341+
public closeTab(): void {
342+
if (this.isPtyLive) {
343+
throw new Error('Cannot close running terminal');
344+
}
345+
this._sendExitMessage();
346+
}
324347
}
325348

326349
/**
@@ -549,6 +572,14 @@ export class OpenShiftTerminalManager implements WebviewViewProvider {
549572
throw new Error(msg);
550573
}
551574

575+
// try to clean up an existing exited terminal in place of this one
576+
for (const existingTerm of this.openShiftTerminals.values()) {
577+
if (!existingTerm.isPtyLive && existingTerm.name === name) {
578+
existingTerm.closeTab();
579+
break;
580+
}
581+
}
582+
552583
const newTermUUID = randomUUID();
553584

554585
// create the object that manages the headless terminal and the pty.

0 commit comments

Comments
 (0)