Skip to content

Commit

Permalink
feat: nested terminal settings and enums
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 committed Apr 5, 2024
1 parent beed319 commit 5c14e5c
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 23 deletions.
22 changes: 16 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,6 @@
"default": "output",
"description": "Where to print the output of tasks. Note that the output panel does not support ANSI colors."
},
"outputToNewTerminal": {
"type": "boolean",
"default": false,
"description": "When using outputTo=terminal whether to use a new Terminal instance or reuse the last instance."
},
"checkForUpdates": {
"type": "boolean",
"default": true,
Expand All @@ -318,6 +313,21 @@
"description": "The order in which to display tasks in the tree view."
}
}
},
"terminal": {
"type": "object",
"description": "Terminal configuration options. Only used when outputTo=terminal.",
"properties": {
"per": {
"type": "string",
"enum": [
"window",
"task"
],
"default": "window",
"description": "When to spawn a new Terminal instance."
}
}
}
}
}
Expand Down Expand Up @@ -359,4 +369,4 @@
"semver": "^7.5.0",
"strip-ansi": "6.0.1"
}
}
}
12 changes: 7 additions & 5 deletions src/services/taskfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from 'path';
import * as semver from 'semver';
import * as vscode from 'vscode';
import * as models from '../models';
import { log, settings } from '../utils';
import { OutputTo, TerminalPer, TreeSort, log, settings } from '../utils';
import stripAnsi = require('strip-ansi');

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

public async runTask(taskName: string, dir?: string, cliArgs?: string): Promise<void> {
if (settings.outputTo === "terminal") {
if (settings.outputTo === OutputTo.terminal) {
log.info(`Running task: "${taskName} ${cliArgs}" in: "${dir}"`);
var terminal: vscode.Terminal;
if (vscode.window.activeTerminal !== undefined && settings.outputToNewTerminal === false) {
if (vscode.window.activeTerminal !== undefined && settings.terminal.per === TerminalPer.window) {
log.info("Using existing terminal");
terminal = vscode.window.activeTerminal;
} else {
log.info("Using new terminal");
terminal = vscode.window.createTerminal("Task");
}
terminal.show();
Expand Down
5 changes: 3 additions & 2 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as elements from './elements';
import * as models from './models';
import * as services from './services';
import { log, settings } from './utils';
import { UpdateOn } from './utils/settings';

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

public async update(checkForUpdates?: boolean): Promise<void> {
Expand Down Expand Up @@ -273,7 +274,7 @@ export class TaskExtension {
// Schedule a new timeout to refresh the task files after 500ms
this._changeTimeout = setTimeout(async () => {
// If manual updating is turned off (update on save)
if (settings.updateOn !== "manual") {
if (settings.updateOn !== UpdateOn.manual) {
await this.refresh(false);
}
}, 200);
Expand Down
89 changes: 79 additions & 10 deletions src/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { log } from './';

class Settings {
private static _instance: Settings;
public updateOn!: string;
public updateOn!: UpdateOn;
public path!: string;
public outputTo!: string;
public outputToNewTerminal!: boolean;
public outputTo!: OutputTo;
public checkForUpdates!: boolean;
public treeNesting!: boolean;
public treeSort!: string;
public tree!: TreeSettings;
public terminal!: TerminalSettings;

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

// Set the properties
this.updateOn = config.get("updateOn") ?? "change";
this.updateOn = config.get("updateOn") ?? UpdateOn.save;
this.path = config.get("path") ?? "task";
this.outputTo = config.get("outputTo") ?? "output";
this.outputToNewTerminal = config.get("outputToNewTerminal") ?? false;
this.outputTo = config.get("outputTo") ?? OutputTo.output;
this.checkForUpdates = config.get("checkForUpdates") ?? true;
this.treeNesting = config.get("tree.nesting") ?? true;
this.treeSort = config.get("tree.sort") ?? "default";
this.tree = new TreeSettings();
this.terminal = new TerminalSettings();
}
}

export enum OutputTo {
output = "output",
terminal = "terminal"
}

export enum UpdateOn {
save = "save",
manual = "manual"
}

class TreeSettings {
private static _instance: TreeSettings;
public nesting!: boolean;
public sort!: TreeSort;

constructor() {
this.update();
}

public static get instance() {
return this._instance ?? (this._instance = new this());
}

// Fetches all the settings from the workspace configuration file
public update() {
log.info("Updating tree settings");

// Get the workspace config
let config = vscode.workspace.getConfiguration("task");

// Set the properties
this.nesting = config.get("tree.nesting") ?? true;
this.sort = config.get("tree.sort") ?? TreeSort.default;
}
}

export enum TreeSort {
default = "default",
alphanumeric = "alphanumeric",
none = "none"
}

class TerminalSettings {
private static _instance: TerminalSettings;
public per!: TerminalPer;

constructor() {
this.update();
}

public static get instance() {
return this._instance ?? (this._instance = new this());
}

// Fetches all the settings from the workspace configuration file
public update() {
log.info("Updating terminal settings");

// Get the workspace config
let config = vscode.workspace.getConfiguration("task");

// Set the properties
this.per = config.get("terminal.per") ?? TerminalPer.window;
}
}

export enum TerminalPer {
window = "window",
task = "task"
}

export const settings = Settings.instance;

0 comments on commit 5c14e5c

Please sign in to comment.