Skip to content

Commit

Permalink
fix: add 'clear-all' command
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenngoclongdev authored Oct 4, 2024
1 parent 24ce2b7 commit b00f0d2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-shirts-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"terminal-keeper": patch
---

fix: add clear all command
25 changes: 22 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
"category": "Terminal Keeper",
"title": "Generate Configuration"
},
{
"command": "terminal-keeper.clear-all",
"category": "Terminal Keeper",
"title": "Clear All"
},
{
"command": "terminal-keeper.kill-all",
"category": "Terminal Keeper",
Expand Down Expand Up @@ -156,6 +161,10 @@
{
"command": "terminal-keeper.copy-command-activity",
"title": "Copy"
},
{
"command": "terminal-keeper.help-and-feedback-activity",
"title": "Help & Feedback"
}
],
"menus": {
Expand All @@ -181,19 +190,29 @@
"group": "activity@1"
},
{
"command": "terminal-keeper.kill-all",
"command": "terminal-keeper.clear-all",
"when": "view == terminalKeeperActivityView",
"group": "activity@2"
},
{
"command": "terminal-keeper.kill-all",
"when": "view == terminalKeeperActivityView",
"group": "activity@3"
},
{
"command": "terminal-keeper.save",
"when": "view == terminalKeeperActivityView",
"group": "tk@1"
"group": "tk1@1"
},
{
"command": "terminal-keeper.remove",
"when": "view == terminalKeeperActivityView",
"group": "tk@2"
"group": "tk1@2"
},
{
"command": "terminal-keeper.help-and-feedback-activity",
"when": "view == terminalKeeperActivityView",
"group": "tk2@1"
}
],
"view/item/context": [
Expand Down
30 changes: 30 additions & 0 deletions src/commands/clearAllAsync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { commands, ProgressLocation, window } from 'vscode';
import { constants } from '../utils/constants';
import { showErrorMessageWithDetail } from '../utils/utils';

export const clearAllAsync = async (): Promise<void> => {
try {
window.withProgress(
{
location: ProgressLocation.Window,
title: 'Terminal Keeper',
cancellable: false
},
async (progress) => {
// If not keep existing terminals, to dispose all
progress.report({ message: 'Clear all terminals...' });

// Clear all existing terminal in parallel
window.terminals.forEach(async (terminal) => {
terminal.show();
await commands.executeCommand('workbench.action.terminal.clear', terminal);
});

// Return a value when the task completes
return 'Clear all of the terminal completed!';
}
);
} catch (error) {
showErrorMessageWithDetail(constants.clearTerminalFailed, error);
}
};
10 changes: 9 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ExtensionContext, Uri, commands, env, window } from 'vscode';
import { activeAsync } from './commands/activeAsync';
import { activeBySessionAsync } from './commands/activeBySessionAsync';
import { activeByTerminalAsync } from './commands/activeByTerminalAsync';
import { clearAllAsync } from './commands/clearAllAsync';
import { generateAsync } from './commands/generateAsync';
import { killAllAsync } from './commands/killAllAsync';
import { migrateAsync } from './commands/migrateAsync';
Expand All @@ -11,7 +12,7 @@ import { saveAsync } from './commands/saveAsync';
import { Configuration } from './configuration/configuration';
import { configFileVersions } from './configuration/interface';
import { TKTreeItem, TreeProvider } from './explorer/tree-provider';
import { extCommands } from './utils/constants';
import { constants, extCommands } from './utils/constants';

export async function activate(context: ExtensionContext) {
// Init configuration
Expand Down Expand Up @@ -45,6 +46,10 @@ export async function activate(context: ExtensionContext) {
commands.registerCommand(extCommands.migrate, async (...args: any[]) => {
await migrateAsync();
}),
// Clear all terminals
commands.registerCommand(extCommands.clearAll, async (...args: any[]) => {
await clearAllAsync();
}),
// Kill all terminals
commands.registerCommand(extCommands.killAll, async (...args: any[]) => {
await killAllAsync();
Expand All @@ -64,6 +69,9 @@ export async function activate(context: ExtensionContext) {
commands.registerCommand(extCommands.collapseAllActivity, async () => {
await commands.executeCommand(`workbench.actions.treeView.${activityId}.collapseAll`);
}),
commands.registerCommand(extCommands.helpAndFeedbackActivity, async () => {
await env.openExternal(Uri.parse(constants.helpAndFeedbackUrl));
}),
commands.registerCommand(extCommands.sendToNewTerminalActivity, async (sessionTreeItem: TKTreeItem) => {
const { sessionId, terminalArrayIndex, label, contextValue } = sessionTreeItem;
if (contextValue === 'terminal-array-context') {
Expand Down
8 changes: 6 additions & 2 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ export const extCommands = {
save: 'terminal-keeper.save',
remove: 'terminal-keeper.remove',
migrate: 'terminal-keeper.migrate',
clearAll: 'terminal-keeper.clear-all',
killAll: 'terminal-keeper.kill-all',
refresh: 'terminal-keeper.refresh-activity',
activeSessionActivity: 'terminal-keeper.active-session-activity',
sendToNewTerminalActivity: 'terminal-keeper.send-to-new-terminal-activity',
sendToCurrentTerminalActivity:'terminal-keeper.send-to-current-terminal-activity',
sendToCurrentTerminalActivity: 'terminal-keeper.send-to-current-terminal-activity',
copyCommandActivity: 'terminal-keeper.copy-command-activity',
collapseAllActivity: 'terminal-keeper.collapse-all-activity'
collapseAllActivity: 'terminal-keeper.collapse-all-activity',
helpAndFeedbackActivity: 'terminal-keeper.help-and-feedback-activity'
};

export const sysCommands = {
Expand All @@ -23,6 +25,7 @@ export const sysCommands = {
export const constants = {
// Common
defaultSession: 'default',
helpAndFeedbackUrl: 'https://github.com/nguyenngoclongdev/vs-terminal-keeper/issues',

// Open the configuration file
openConfigurationFailed: 'Failed to open the configuration file!',
Expand All @@ -40,6 +43,7 @@ export const constants = {
activeSessionFailed: 'Failed to activate the session.',
activeTerminalFailed: 'Failed to activate the terminal.',
killTerminalFailed: 'Failed to kill the terminals.',
clearTerminalFailed: 'Failed to clear the terminals.',
workingDirNotExist: 'The terminal "{terminal}" cannot find the current working directory "{cwd}".',

// Valid configuration file
Expand Down

0 comments on commit b00f0d2

Please sign in to comment.