xiaguangbo
xiaguangbo

Reputation: 115

How to close the task terminal automatically after vscode debugging

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

Answers (2)

Gangula
Gangula

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 new close property.
Setting close to true 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
  }
}

TIP

Note that it is recommended to switch to the "Problems" tab in the terminal after using the close option - Reference

Upvotes: 6

xiaguangbo
xiaguangbo

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

Related Questions