【问题标题】:How to close the task terminal automatically after vscode debuggingvscode调试后如何自动关闭任务终端
【发布时间】:2020-02-17 04:17:58
【问题描述】:

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
         ]
    }
]
}

OpenOCD服务不会像make命令那样自动结束,只需要关闭终端或者执行Ctrl+C即可。 调试后如何自动关闭任务终端? 或者在任务终端自动执行Ctrl+C命令,结束Openocd服务。 目前使用的closeOpenOCDTerminal方法需要手动点击弹出列表。

【问题讨论】:

  • 您的startDebug 在launch.json 或tasks.json 中吗?不应该在launch.json中吗?

标签: c


【解决方案1】:
{
    "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"
        }
    ]
}

这个例子恰好关闭了任务终端。

【讨论】:

    【解决方案2】:

    VSCode (1.57) 中的 tasks.json 文件现在有一个名为 close 的属性位于 presentation 属性中。你可以用它来关闭终端。

    Automatically close task terminals

    任务presentation 属性有一个新的close 属性。
    close 设置为true 将导致终端在任务退出时关闭。

    {
      "type": "shell",
      "command": "node build/lib/preLaunch.js",
      "label": "Ensure Prelaunch Dependencies",
      "presentation": {
          "reveal": "silent",
          "close": true
      }
    }
    

    提示

    注意,建议在使用关闭选项后切换到终端中的“问题”选项卡-Reference

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 2015-11-05
      • 2016-09-25
      • 2021-07-09
      • 1970-01-01
      相关资源
      最近更新 更多