Open VsCode terminal programmatically in the simplest way possible.
Launch VsCode's debugger programmatically, passing in your launch configuration.
If you're using VSCode, and you constantly find yourself in a situation where you need to open multiple vscode terminals, where each one runs a different server (or a script), then this is the package for you.
Prerequisites:
- VSCode as your IDE
-
Open Terminal Programmatically
extension installed
Most of the work would be done by the extension. This package just acts as its wrapper, providing you with 2 easy-to-use functions, with hints, autocomplete, and correct typings.
Go over to the extension market on VSCode, search & download Open Terminal Programmatically
.
Run one of these:
(depending on your package manager)
npm install -g open-terminal-programmatically
pnpm add -g open-terminal-programmatically
yarn add -g open-terminal-programmatically
import { openTerminal } from 'open-terminal-programmatically';
The openTerminal
is a function you can use to open new terminals in VSCode, or launch/attach a new debug process.
It accept these following options:
type: boolean
(Optional)
default: false
If set to true
, command will open up VSCode's debug terminal, which would appear under the TERMINAL tab.
If set toe true, the config
prop should then be of type DebugConfig
, else, it should be of type TerminalConfig
. (more on those 2 types is down below).
type: number (Optional)
Puts a delay of X milliseconds after the execution.
Sometimes you're running 2 servers, where one is dependant on the other being ready. You can put some delay between them by using the delayNextFor
property.
type: TerminalConfig
| DebugConfig
(Required)
Depending on whether you want a debugger terminal, or a regular terminal, you should pass the proper form of corresponding config.
type: string (Required)
The command to execute in that new terminal to be opened.
This is the only required field on config
.
type: string (Optional)
The name of the new terminal to be opened.
Will appear in your IDE.
type: 'red' | 'green' | 'blue' | 'yellow' | 'magenta' | 'cyan' | 'black' | 'white'; (Optional) default: 'white'
The name of the terminal will be colored in that color.
type: boolean (Optional) default: false
Should the terminal gain focus once it's open or not.
type: Array (Optional)
You can add additional run time args to the command to execute.
These props are all the props you usually put under your launch config, under your ".vscode/launch.json" file. Read more about those in the official VSCode documentation.