Skip to content

Commit

Permalink
fix: active terminal array from activity
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenngoclongdev authored Sep 17, 2024
1 parent 6355d67 commit 1aaea6e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-nails-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"terminal-keeper": patch
---

fix: active terminal array from activity
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 14 additions & 7 deletions src/commands/activeByTerminalAsync.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TerminalApi, ThemeService } from '@vscode-utility/terminal-browserify';
import { window } from 'vscode';
import { Configuration } from '../configuration/configuration';
import { constants } from '../utils/constants';
import { findTerminal } from '../utils/find-terminal-in-config';
import { TerminalApi, ThemeService } from '@vscode-utility/terminal-browserify';
import { showErrorMessageWithDetail } from '../utils/utils';

export const activeByTerminalAsync = async (
Expand All @@ -18,25 +18,32 @@ export const activeByTerminalAsync = async (
}

// Read the config
const { createTerminal, getCwdPath } = TerminalApi.instance();
const configInstance = Configuration.instance();
const config = await configInstance.load();
const { theme = 'default', noClear = false } = config;
const themeService = new ThemeService(theme);

const { createTerminal, getCwdPath } = TerminalApi.instance();
// Set terminal cwd
const terminals = Array.isArray(terminal) ? terminal : [terminal];
for (let i = 0; i < terminals.length; i++) {
const tm = terminals[i];

// Kill previous terminal and create new terminal from session
const cwdPath = await getCwdPath(tm.cwd);
if (cwdPath) {
tm.cwdPath = cwdPath;
}
}

const themeService = new ThemeService(theme);
createTerminal(themeService, tm, { kind: 'standalone' }, noClear);
// Create terminal
if (Array.isArray(terminal)) {
const parentTerminal = createTerminal(themeService, terminal[0], { kind: 'parent' }, noClear);
for (let i = terminal.length - 1; i >= 1; i--) {
createTerminal(themeService, terminal[i], { kind: 'children', parentTerminal }, noClear);
}
} else {
createTerminal(themeService, terminal, { kind: 'standalone' }, noClear);
}
} catch (error) {
showErrorMessageWithDetail(constants.activeSessionFailed, error);
showErrorMessageWithDetail(constants.activeTerminalFailed, error);
}
};
1 change: 1 addition & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const constants = {
selectSessionActiveTitle: 'Select a session to activate',
selectSessionActivePlaceHolder: 'Select session...',
activeSessionFailed: 'Failed to activate the session.',
activeTerminalFailed: 'Failed to activate the terminal.',
killTerminalFailed: 'Failed to kill the terminals.',
workingDirNotExist: 'The terminal "{terminal}" cannot find the current working directory "{cwd}".',

Expand Down

0 comments on commit 1aaea6e

Please sign in to comment.