Skip to content

Commit 5c14e5c

Browse files
committed
feat: nested terminal settings and enums
1 parent beed319 commit 5c14e5c

File tree

4 files changed

+105
-23
lines changed

4 files changed

+105
-23
lines changed

package.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,6 @@
288288
"default": "output",
289289
"description": "Where to print the output of tasks. Note that the output panel does not support ANSI colors."
290290
},
291-
"outputToNewTerminal": {
292-
"type": "boolean",
293-
"default": false,
294-
"description": "When using outputTo=terminal whether to use a new Terminal instance or reuse the last instance."
295-
},
296291
"checkForUpdates": {
297292
"type": "boolean",
298293
"default": true,
@@ -318,6 +313,21 @@
318313
"description": "The order in which to display tasks in the tree view."
319314
}
320315
}
316+
},
317+
"terminal": {
318+
"type": "object",
319+
"description": "Terminal configuration options. Only used when outputTo=terminal.",
320+
"properties": {
321+
"per": {
322+
"type": "string",
323+
"enum": [
324+
"window",
325+
"task"
326+
],
327+
"default": "window",
328+
"description": "When to spawn a new Terminal instance."
329+
}
330+
}
321331
}
322332
}
323333
}
@@ -359,4 +369,4 @@
359369
"semver": "^7.5.0",
360370
"strip-ansi": "6.0.1"
361371
}
362-
}
372+
}

src/services/taskfile.ts

Lines changed: 7 additions & 5 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 { log, settings } from '../utils';
9+
import { OutputTo, TerminalPer, TreeSort, log, settings } from '../utils';
1010
import stripAnsi = require('strip-ansi');
1111

1212
const octokit = new Octokit();
@@ -174,8 +174,8 @@ class TaskfileService {
174174
return await new Promise((resolve, reject) => {
175175
let additionalFlags = "";
176176
// Sorting
177-
if (settings.treeSort !== "default") {
178-
additionalFlags = ` --sort ${settings.treeSort}`;
177+
if (settings.tree.sort !== TreeSort.default) {
178+
additionalFlags = ` --sort ${settings.tree.sort}`;
179179
}
180180
let command = this.command(`--list-all --json${additionalFlags}`);
181181
cp.exec(command, { cwd: dir }, (err: cp.ExecException | null, stdout: string, stderr: string) => {
@@ -222,12 +222,14 @@ class TaskfileService {
222222
}
223223

224224
public async runTask(taskName: string, dir?: string, cliArgs?: string): Promise<void> {
225-
if (settings.outputTo === "terminal") {
225+
if (settings.outputTo === OutputTo.terminal) {
226226
log.info(`Running task: "${taskName} ${cliArgs}" in: "${dir}"`);
227227
var terminal: vscode.Terminal;
228-
if (vscode.window.activeTerminal !== undefined && settings.outputToNewTerminal === false) {
228+
if (vscode.window.activeTerminal !== undefined && settings.terminal.per === TerminalPer.window) {
229+
log.info("Using existing terminal");
229230
terminal = vscode.window.activeTerminal;
230231
} else {
232+
log.info("Using new terminal");
231233
terminal = vscode.window.createTerminal("Task");
232234
}
233235
terminal.show();

src/task.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as elements from './elements';
33
import * as models from './models';
44
import * as services from './services';
55
import { log, settings } from './utils';
6+
import { UpdateOn } from './utils/settings';
67

78
export class TaskExtension {
89
private _taskfiles: models.Taskfile[] = [];
@@ -13,7 +14,7 @@ export class TaskExtension {
1314
constructor() {
1415
this._activityBar = new elements.ActivityBar();
1516
this._watcher = vscode.workspace.createFileSystemWatcher("**/*.{yml,yaml}");
16-
this.setTreeNesting(settings.treeNesting);
17+
this.setTreeNesting(settings.tree.nesting);
1718
}
1819

1920
public async update(checkForUpdates?: boolean): Promise<void> {
@@ -273,7 +274,7 @@ export class TaskExtension {
273274
// Schedule a new timeout to refresh the task files after 500ms
274275
this._changeTimeout = setTimeout(async () => {
275276
// If manual updating is turned off (update on save)
276-
if (settings.updateOn !== "manual") {
277+
if (settings.updateOn !== UpdateOn.manual) {
277278
await this.refresh(false);
278279
}
279280
}, 200);

src/utils/settings.ts

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import { log } from './';
33

44
class Settings {
55
private static _instance: Settings;
6-
public updateOn!: string;
6+
public updateOn!: UpdateOn;
77
public path!: string;
8-
public outputTo!: string;
9-
public outputToNewTerminal!: boolean;
8+
public outputTo!: OutputTo;
109
public checkForUpdates!: boolean;
11-
public treeNesting!: boolean;
12-
public treeSort!: string;
10+
public tree!: TreeSettings;
11+
public terminal!: TerminalSettings;
1312

1413
constructor() {
1514
this.update();
@@ -27,14 +26,84 @@ class Settings {
2726
let config = vscode.workspace.getConfiguration("task");
2827

2928
// Set the properties
30-
this.updateOn = config.get("updateOn") ?? "change";
29+
this.updateOn = config.get("updateOn") ?? UpdateOn.save;
3130
this.path = config.get("path") ?? "task";
32-
this.outputTo = config.get("outputTo") ?? "output";
33-
this.outputToNewTerminal = config.get("outputToNewTerminal") ?? false;
31+
this.outputTo = config.get("outputTo") ?? OutputTo.output;
3432
this.checkForUpdates = config.get("checkForUpdates") ?? true;
35-
this.treeNesting = config.get("tree.nesting") ?? true;
36-
this.treeSort = config.get("tree.sort") ?? "default";
33+
this.tree = new TreeSettings();
34+
this.terminal = new TerminalSettings();
3735
}
3836
}
3937

38+
export enum OutputTo {
39+
output = "output",
40+
terminal = "terminal"
41+
}
42+
43+
export enum UpdateOn {
44+
save = "save",
45+
manual = "manual"
46+
}
47+
48+
class TreeSettings {
49+
private static _instance: TreeSettings;
50+
public nesting!: boolean;
51+
public sort!: TreeSort;
52+
53+
constructor() {
54+
this.update();
55+
}
56+
57+
public static get instance() {
58+
return this._instance ?? (this._instance = new this());
59+
}
60+
61+
// Fetches all the settings from the workspace configuration file
62+
public update() {
63+
log.info("Updating tree settings");
64+
65+
// Get the workspace config
66+
let config = vscode.workspace.getConfiguration("task");
67+
68+
// Set the properties
69+
this.nesting = config.get("tree.nesting") ?? true;
70+
this.sort = config.get("tree.sort") ?? TreeSort.default;
71+
}
72+
}
73+
74+
export enum TreeSort {
75+
default = "default",
76+
alphanumeric = "alphanumeric",
77+
none = "none"
78+
}
79+
80+
class TerminalSettings {
81+
private static _instance: TerminalSettings;
82+
public per!: TerminalPer;
83+
84+
constructor() {
85+
this.update();
86+
}
87+
88+
public static get instance() {
89+
return this._instance ?? (this._instance = new this());
90+
}
91+
92+
// Fetches all the settings from the workspace configuration file
93+
public update() {
94+
log.info("Updating terminal settings");
95+
96+
// Get the workspace config
97+
let config = vscode.workspace.getConfiguration("task");
98+
99+
// Set the properties
100+
this.per = config.get("terminal.per") ?? TerminalPer.window;
101+
}
102+
}
103+
104+
export enum TerminalPer {
105+
window = "window",
106+
task = "task"
107+
}
108+
40109
export const settings = Settings.instance;

0 commit comments

Comments
 (0)