Reputation: 115
launch.json
...
"preLaunchTask": "startDebug",
"postDebugTask": "closeOpenOCDTerminal"
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "startDebug",
"type": "shell",
"command": "make -j4; openocd -f interface/cmsis-dap.cfg -c 'transport select swd' -f target/stm32f1x.cfg",
"isBackground": true,
"problemMatcher": {
"pattern": {
"regexp": "."
},
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": "."
}
}
},
{
"label": "closeOpenOCDTerminal",
"type": "process",
"command":[
"${command:workbench.action.tasks.terminate}",
// "${command:workbench.action.acceptSelectedQuickOpenItem}" //invalid
]
}
]
}
The OpenOCD service does not end automatically like the make command, only depends on closing the terminal or executing Ctrl + C. How to automatically close the task terminal after debugging? Or execute Ctrl + C command automatically in the task terminal to end the Openocd service. The currently used closeOpenOCDTerminal method requires manual clicking on the pop-up list.
Upvotes: 8
Views: 7072
Reputation: 7274
The tasks.json file in VSCode (1.57) now has a property called close
in the presentation
property. And you can use it to close the terminal.
Automatically close task terminals
The task
presentation
property has a newclose
property.
Settingclose
totrue
will cause the terminal to close when the task exits.{ "type": "shell", "command": "node build/lib/preLaunch.js", "label": "Ensure Prelaunch Dependencies", "presentation": { "reveal": "silent", "close": true } }
Note that it is recommended to switch to the "Problems" tab in the terminal after using the close option - Reference
Upvotes: 6
Reputation: 115
{
"version": "2.0.0",
"tasks": [
{
"label": "start",
"type": "shell",
"command": "make -j4; openocd -f interface/cmsis-dap.cfg -c 'transport select swd' -f target/stm32f1x.cfg",
"isBackground": true,
"problemMatcher": {
"pattern": {
"regexp": "."
},
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": "."
}
}
},
{
"label": "stop",
"command": "echo ${input:terminate}",
"type": "shell",
}
],
"inputs": [
{
"id": "terminate",
"type": "command",
"command": "workbench.action.tasks.terminate",
"args": "terminateAll"
}
]
}
This example happens to close the task terminal.
Upvotes: 2