From 69e775db7a48bc6af7eb1af1921de4068ec7b2da Mon Sep 17 00:00:00 2001 From: eyal-hl Date: Wed, 27 Mar 2024 01:54:05 +0200 Subject: [PATCH 1/3] fixed eslint problems --- .eslintrc.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 95c62b9..1e36b45 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,6 +9,11 @@ "extends": ["plugin:prettier/recommended"], "plugins": ["prettier"], "rules": { - "prettier/prettier": "error" + "prettier/prettier": [ + "error", + { + "endOfLine": "auto" + } + ] } } From 27d450ff38a8f0a294afe9a8f50f627c7f16563d Mon Sep 17 00:00:00 2001 From: eyal-hl Date: Wed, 27 Mar 2024 01:55:01 +0200 Subject: [PATCH 2/3] Now also supporting map of presets of terminals --- package-lock.json | 4 +- package.json | 95 +++++++++++++++++++++++++++++++---------- src/model.ts | 2 +- src/restoreTerminals.ts | 31 +++++++++++++- 4 files changed, 106 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index bef78ab..3dc9fa6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "restore-terminals", - "version": "1.1.6", + "version": "1.1.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "restore-terminals", - "version": "1.1.6", + "version": "1.1.8", "dependencies": { "text-encoding": "^0.7.0" }, diff --git a/package.json b/package.json index 0f6fcf3..da25c03 100644 --- a/package.json +++ b/package.json @@ -49,40 +49,91 @@ "description": "If you find restore terminals glitching out, or running some commands in the wrong window, you might want to try increasing this number to further delay the processing of actions. If you find it taking too long to open the terminal windows, you can try reducing this number, be be cautious as if it's too fast it will bug out." }, "restoreTerminals.terminals": { - "type": "array", - "items": { - "properties": { - "splitTerminals": { + "type": [ + "array", + "object" + ], + "oneOf": [ + { + "type": "object", + "additionalProperties": { "type": "array", "items": { "properties": { - "name": { - "type": "string", - "description": "The name to give the terminal window" - }, - "icon": { - "type": "string", - "description": "The icon to give the terminal window" - }, - "commands": { + "splitTerminals": { "type": "array", - "description": "The shell commands to execute when this terminal opens.", "items": { "properties": { + "name": { + "type": "string", + "description": "The name to give the terminal window" + }, + "icon": { + "type": "string", + "description": "The icon to give the terminal window" + }, + "commands": { + "type": "array", + "description": "The shell commands to execute when this terminal opens.", + "items": { + "properties": { + "type": "string", + "description": "A shell command to run." + } + } + }, + "shouldRunCommands": { + "type": "boolean", + "description": "Whether to actually run the commands in the terminal, or just paste them there." + } + }, + "additionalProperties": false + } + } + }, + "additionalProperties": false + } + } + }, + { + "type": "array", + "items": { + "properties": { + "splitTerminals": { + "type": "array", + "items": { + "properties": { + "name": { + "type": "string", + "description": "The name to give the terminal window" + }, + "icon": { "type": "string", - "description": "A shell command to run." + "description": "The icon to give the terminal window" + }, + "commands": { + "type": "array", + "description": "The shell commands to execute when this terminal opens.", + "items": { + "properties": { + "type": "string", + "description": "A shell command to run." + } + } + }, + "shouldRunCommands": { + "type": "boolean", + "description": "Whether to actually run the commands in the terminal, or just paste them there." } - } - }, - "shouldRunCommands": { - "type": "boolean", - "description": "Whether to actually run the commands in the terminal, or just paste them there." + }, + "additionalProperties": false } } - } + }, + "additionalProperties": false } } - } + ] } } } diff --git a/src/model.ts b/src/model.ts index 3019b89..e782b26 100644 --- a/src/model.ts +++ b/src/model.ts @@ -13,7 +13,7 @@ export interface TerminalWindow { export interface Configuration { keepExistingTerminalsOpen?: boolean; artificialDelayMilliseconds?: number; - terminalWindows?: TerminalWindow[]; + terminalWindows?: TerminalWindow[] | Map; runOnStartup?: boolean; } diff --git a/src/restoreTerminals.ts b/src/restoreTerminals.ts index f98bf2c..a88f60f 100644 --- a/src/restoreTerminals.ts +++ b/src/restoreTerminals.ts @@ -8,7 +8,7 @@ const MAX_TERM_CHECK_ATTEMPTS = 500; //this times SPLIT_TERM_CHECK_DELAY is the export default async function restoreTerminals(configuration: Configuration) { console.log("restoring terminals", configuration); - const { + let { keepExistingTerminalsOpen, artificialDelayMilliseconds, terminalWindows, @@ -19,6 +19,35 @@ export default async function restoreTerminals(configuration: Configuration) { return; } + if (!(terminalWindows instanceof Array) && terminalWindows !== null) { + terminalWindows = new Map(Object.entries(terminalWindows)); + if (!terminalWindows.size) { + vscode.window.showInformationMessage( + "Empty terminal window configuration provided to restore terminals with." + ); //this might be annoying + return; + } + + if (terminalWindows.size > 1) { + const picked = await vscode.window.showQuickPick( + Array.from(terminalWindows.keys()) + ); + if (!picked) { + return; + } + terminalWindows = terminalWindows.get(picked) ?? []; + } else { + terminalWindows = Array.from(terminalWindows.values())[0]; + } + } + + if (!terminalWindows.length) { + vscode.window.showInformationMessage( + "Empty terminal window configuration provided to restore terminals with." + ); //this might be annoying + return; + } + if (vscode.window.activeTerminal && !keepExistingTerminalsOpen) { vscode.window.terminals.forEach((terminal) => { //i think calling terminal.dispose before creating the new termials causes error because the terminal has disappeard and it fux up. we can do it after, and check that the terminal we are deleting is not in the list of terminals we just created From f5e0ea084d307cc0ff48ecb453be958a624d06d2 Mon Sep 17 00:00:00 2001 From: eyal-hl Date: Wed, 27 Mar 2024 02:02:06 +0200 Subject: [PATCH 3/3] updated readme --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/README.md b/README.md index 0caaf58..69f686e 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,55 @@ Simply configure your VSCode settings JSON file to look something like this: ] ``` +Or named configurations that you can choose between: + +``` + "restoreTerminals.terminals": { + "dev": [ + { + "splitTerminals": [ + { + "name": "server", + "commands": ["npm i", "npm run dev"] + }, + { + "name": "client", + "commands": ["npm run dev:client"] + } + ] + }, + { + "splitTerminals": [ + { + "name": "worker", + "commands": ["npm-run-all --parallel redis tsc-watch-start worker"] + } + ] + } + ], + "test": [ + { + "splitTerminals": [ + { + "name": "test", + "commands": ["jest --watch"], + "shouldRunCommands": false + } + ], + }, + { + "splitTerminals": [ + { + "name": "build & e2e", + "commands": ["npm run eslint", "npm run build", "npm run e2e"], + "shouldRunCommands": false + } + ], + } + ] + } +``` + The outer array represents a integrated VSCode terminal window, and the `splitTerminals` array contains the information about how each terminal window should be split up. You can also use a custom config file under. The file should be at `.vscode/restore-terminals.json` in any workspace you want. A sample config file is [here](https://github.com/EthanSK/restore-terminals-vscode/blob/master/sample-test-project/.vscode/restore-terminals.json). If this config file is present, Restore Terminals will try and load settings from it first, then use `settings.json` as a fallback.