Skip to content

Terminals

VSCode provides a powerful terminal system that allows you to run shell commands in the integrated terminal. reactive-vscode provides a set of composable functions to create and manage terminals in a reactive way.

Create a Terminal

useTerminal creates a terminal via window.createTerminal. The params are the same as window.createTerminal.
ts
import { 
defineExtension
,
useTerminal
} from 'reactive-vscode'
export =
defineExtension
(() => {
const {
terminal
,
name
,
processId
,
creationOptions
,
exitStatus
,
sendText
,
show
,
hide
,
state
,
} =
useTerminal
('My Terminal', '/bin/bash')
})

Create a Controlled Terminal

useControlledTerminal creates a terminal which allows you to control its lifecycle. The params are the same as window.createTerminal.
ts
import { 
defineExtension
,
useControlledTerminal
} from 'reactive-vscode'
export =
defineExtension
(() => {
const {
terminal
,
getIsActive
,
show
,
sendText
,
close
,
state
,
} =
useControlledTerminal
('My Terminal', '/bin/bash')
})

The Active Terminal

You can use useActiveTerminal to get the currently active terminal.

ts
import { 
defineExtension
,
useActiveTerminal
} from 'reactive-vscode'
export =
defineExtension
(() => {
const
activeTerminal
=
useActiveTerminal
()
})

All Opened Terminals

You can use useOpenedTerminals to get all open terminals.

ts
import { 
defineExtension
,
useOpenedTerminals
} from 'reactive-vscode'
export =
defineExtension
(() => {
const
terminals
=
useOpenedTerminals
()
})

Get Terminal State

You can use useTerminalState to get the state of an existing terminal.

ts
import { 
defineExtension
,
useActiveTerminal
,
useOpenedTerminals
,
useTerminalState
} from 'reactive-vscode'
export =
defineExtension
(() => {
const
activeTerminal
=
useActiveTerminal
()
const
activeTerminalState
=
useTerminalState
(
activeTerminal
)
const
allTerminals
=
useOpenedTerminals
()
const
firstTerminalState
=
useTerminalState
(() =>
allTerminals
.
value
[0])
})