Files
bruno/packages/bruno-app/src/utils/terminal.js
Chirag Chandrashekhar 9159f523d9 Inbuilt Terminal (#6066)
* add: terminal

* added support for multiple terminal sessions and opening terminal from collection's working directory

* Use PowerShell as default shell on Windows

Replace cmd.exe with powershell.exe for terminal sessions on Windows.
Falls back to PWSH environment variable if set (for PowerShell Core).

* refactor(ui): improved session list by moving path display to hover for cleaner view

* chore: format

* refactor: improve terminal code quality and UI consistency

- Add terminal icon to 'Open in Terminal' dropdown item in CollectionItem
- Remove unused imports and functions (IconPlus, callIpc, canWriteToTerminal)
- Fix React key prop placement in SessionList component
- Replace deprecated substr with substring in terminal session ID generation
- Improve error handling for terminal cleanup on app quit
- Simplify terminal cleanup logic in window close handler

---------

Co-authored-by: naman-bruno <naman@usebruno.com>
Co-authored-by: Sid <siddharth@usebruno.com>
2025-12-03 17:48:28 +05:30

33 lines
1.2 KiB
JavaScript

import { openConsole, setActiveTab } from 'providers/ReduxStore/slices/logs';
import { getSessionId } from 'components/Devtools/Console/TerminalTab';
/**
* Opens the devtools console and switches to the terminal tab
* Optionally opens/switches to a terminal session at a specific CWD
* @param {Function} dispatch - Redux dispatch function
* @param {string} [cwd] - Optional CWD path. If provided, checks for existing session at that CWD or creates new one
*/
export const openDevtoolsAndSwitchToTerminal = async (dispatch, cwd = null) => {
// Open console if closed
dispatch(openConsole());
// Switch to terminal tab
dispatch(setActiveTab('terminal'));
// If CWD is provided, dispatch event to TerminalTab to handle session selection/creation
if (cwd) {
// Small delay to ensure terminal tab is mounted
setTimeout(() => {
window.dispatchEvent(new CustomEvent('terminal:open-at-cwd', { detail: { cwd } }));
}, 100);
}
};
/**
* Gets the current terminal session ID if a terminal session is running
* @returns {string|null} The session ID if terminal session exists, null otherwise
*/
export const getSessionID = () => {
return getSessionId();
};