Skip to content

Commit ff6fbaa

Browse files
committed
feat: terminal.close and terminal improvements
1 parent 5c14e5c commit ff6fbaa

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Added `terminal.per` setting to allow a new terminal per task (#125, #126 by
6+
@yoiang).
7+
- Added `terminal.close` setting to control if the existing terminal should
8+
close before running another task (by @pd93).
9+
- General improvements to how terminals are handled (by @pd93).
10+
311
## v0.3.2 - 2023-11-20
412

513
- Fixed another small bug with the new argument passing (#94 by @MaxCheetham).

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@
326326
],
327327
"default": "window",
328328
"description": "When to spawn a new Terminal instance."
329+
},
330+
"close": {
331+
"type": "string",
332+
"enum": [
333+
"never",
334+
"onNextTask"
335+
],
336+
"default": "never",
337+
"description": "When to close the Terminal instance."
329338
}
330339
}
331340
}

src/services/taskfile.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from 'path';
66
import * as semver from 'semver';
77
import * as vscode from 'vscode';
88
import * as models from '../models';
9-
import { OutputTo, TerminalPer, TreeSort, log, settings } from '../utils';
9+
import { OutputTo, TerminalClose, TerminalPer, TreeSort, log, settings } from '../utils';
1010
import stripAnsi = require('strip-ansi');
1111

1212
const octokit = new Octokit();
@@ -34,6 +34,7 @@ const errCodeTaskCalledTooManyTimes = 204;
3434
class TaskfileService {
3535
private static _instance: TaskfileService;
3636
private static outputChannel: vscode.OutputChannel;
37+
private static terminal: vscode.Terminal;
3738
private lastTaskName: string | undefined;
3839
private lastTaskDir: string | undefined;
3940
private version: semver.SemVer | undefined;
@@ -224,16 +225,18 @@ class TaskfileService {
224225
public async runTask(taskName: string, dir?: string, cliArgs?: string): Promise<void> {
225226
if (settings.outputTo === OutputTo.terminal) {
226227
log.info(`Running task: "${taskName} ${cliArgs}" in: "${dir}"`);
227-
var terminal: vscode.Terminal;
228-
if (vscode.window.activeTerminal !== undefined && settings.terminal.per === TerminalPer.window) {
229-
log.info("Using existing terminal");
230-
terminal = vscode.window.activeTerminal;
231-
} else {
228+
if (TaskfileService.terminal !== undefined && settings.terminal.close === TerminalClose.onNextTask) {
229+
log.info("Closing old terminal");
230+
TaskfileService.terminal.dispose();
231+
}
232+
if (TaskfileService.terminal === undefined || TaskfileService.terminal.exitStatus !== undefined || settings.terminal.per === TerminalPer.task) {
232233
log.info("Using new terminal");
233-
terminal = vscode.window.createTerminal("Task");
234+
TaskfileService.terminal = vscode.window.createTerminal("Task");
235+
} else {
236+
log.info("Using existing terminal");
234237
}
235-
terminal.show();
236-
terminal.sendText(this.command(taskName, cliArgs));
238+
TaskfileService.terminal.show();
239+
TaskfileService.terminal.sendText(this.command(taskName, cliArgs));
237240
} else {
238241
return await new Promise((resolve) => {
239242
log.info(`Running task: "${taskName}" in: "${dir}"`);

src/utils/settings.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export enum TreeSort {
8080
class TerminalSettings {
8181
private static _instance: TerminalSettings;
8282
public per!: TerminalPer;
83+
public close!: TerminalClose;
8384

8485
constructor() {
8586
this.update();
@@ -98,6 +99,7 @@ class TerminalSettings {
9899

99100
// Set the properties
100101
this.per = config.get("terminal.per") ?? TerminalPer.window;
102+
this.close = config.get("terminal.close") ?? TerminalClose.never;
101103
}
102104
}
103105

@@ -106,4 +108,10 @@ export enum TerminalPer {
106108
task = "task"
107109
}
108110

111+
export enum TerminalClose {
112+
never = "never",
113+
taskComplete = "taskComplete",
114+
onNextTask = "onNextTask"
115+
}
116+
109117
export const settings = Settings.instance;

0 commit comments

Comments
 (0)