diff --git a/.changeset/purple-snails-unite.md b/.changeset/purple-snails-unite.md new file mode 100644 index 0000000..5d3be44 --- /dev/null +++ b/.changeset/purple-snails-unite.md @@ -0,0 +1,5 @@ +--- +"terminal-keeper": patch +--- + +fix: add abort all functions in activity diff --git a/package.json b/package.json index 943a15d..5e99e24 100644 --- a/package.json +++ b/package.json @@ -106,6 +106,11 @@ "category": "Terminal Keeper", "title": "Clear All" }, + { + "command": "terminal-keeper.abort-all", + "category": "Terminal Keeper", + "title": "Abort All" + }, { "command": "terminal-keeper.kill-all", "category": "Terminal Keeper", @@ -195,10 +200,15 @@ "group": "activity@2" }, { - "command": "terminal-keeper.kill-all", + "command": "terminal-keeper.abort-all", "when": "view == terminalKeeperActivityView", "group": "activity@3" }, + { + "command": "terminal-keeper.kill-all", + "when": "view == terminalKeeperActivityView", + "group": "activity@4" + }, { "command": "terminal-keeper.save", "when": "view == terminalKeeperActivityView", diff --git a/src/commands/abortAllAsync.ts b/src/commands/abortAllAsync.ts new file mode 100644 index 0000000..4ba17b7 --- /dev/null +++ b/src/commands/abortAllAsync.ts @@ -0,0 +1,29 @@ +import { ProgressLocation, window } from 'vscode'; +import { constants } from '../utils/constants'; +import { showErrorMessageWithDetail } from '../utils/utils'; + +export const abortAllAsync = async (): Promise => { + try { + window.withProgress( + { + location: ProgressLocation.Window, + title: 'Terminal Keeper', + cancellable: false + }, + async (progress) => { + // If not keep existing terminals, to dispose all + progress.report({ message: 'Abort all terminals...' }); + + // Clear all existing terminal in parallel + window.terminals.forEach(async (terminal) => { + terminal.sendText(`\u0003`, true); + }); + + // Return a value when the task completes + return 'Abort all of the terminal completed!'; + } + ); + } catch (error) { + showErrorMessageWithDetail(constants.abortTerminalFailed, error); + } +}; diff --git a/src/commands/killAllAsync.ts b/src/commands/killAllAsync.ts index 0bf9347..c197906 100644 --- a/src/commands/killAllAsync.ts +++ b/src/commands/killAllAsync.ts @@ -16,7 +16,9 @@ export const killAllAsync = async (): Promise => { progress.report({ message: 'Kill all terminals...' }); // Kill all existing terminal in parallel - await killAllTerminal(); + if (window.terminals && window.terminals.length > 0) { + await killAllTerminal(); + } // Return a value when the task completes return 'Kill all of the terminal completed!'; diff --git a/src/extension.ts b/src/extension.ts index c394325..2b35444 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,4 +1,5 @@ import { ExtensionContext, Uri, commands, env, window } from 'vscode'; +import { abortAllAsync } from './commands/abortAllAsync'; import { activeAsync } from './commands/activeAsync'; import { activeBySessionAsync } from './commands/activeBySessionAsync'; import { activeByTerminalAsync } from './commands/activeByTerminalAsync'; @@ -50,6 +51,10 @@ export async function activate(context: ExtensionContext) { commands.registerCommand(extCommands.clearAll, async (...args: any[]) => { await clearAllAsync(); }), + // Abort all terminals + commands.registerCommand(extCommands.abortAll, async (...args: any[]) => { + await abortAllAsync(); + }), // Kill all terminals commands.registerCommand(extCommands.killAll, async (...args: any[]) => { await killAllAsync(); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 12dd57e..d08ba79 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -6,6 +6,7 @@ export const extCommands = { remove: 'terminal-keeper.remove', migrate: 'terminal-keeper.migrate', clearAll: 'terminal-keeper.clear-all', + abortAll: 'terminal-keeper.abort-all', killAll: 'terminal-keeper.kill-all', refresh: 'terminal-keeper.refresh-activity', activeSessionActivity: 'terminal-keeper.active-session-activity', @@ -44,6 +45,7 @@ export const constants = { activeTerminalFailed: 'Failed to activate the terminal.', killTerminalFailed: 'Failed to kill the terminals.', clearTerminalFailed: 'Failed to clear the terminals.', + abortTerminalFailed: 'Failed to abort the terminals.', workingDirNotExist: 'The terminal "{terminal}" cannot find the current working directory "{cwd}".', // Valid configuration file