如何配置 VS Code 在任务完成后自动隐藏而不是关闭终端面板

IMT*_*Man 3 visual-studio-code vscode-tasks

任务完成后,终端将保持打开状态。有没有办法自动隐藏它?

我不是谈论关闭窗口,如https://code.visualstudio.com/updates/v1_57#_automatically-close-task-terminals中所述,因为这将删除所有输出。

我只想隐藏终端,以便在需要时仍然可以通过打开终端面板返回到输出。

在此输入图像描述

Mar*_*ark 6

Hopefully there is a better way that I don't know of but this works. Make these tasks in your tasks.json:

{
  "version": "2.0.0",

  "tasks": [
    {
      "label": "echo and hide",
      "dependsOrder": "sequence",
      "dependsOn": [
        "simple echo",
        "hide terminal"
      ]
    },
    {
      "label": "simple echo",
      "command": "echo I have been hidden",
      "type": "shell",
      "problemMatcher": []
    },
    {
      "label": "hide terminal",
      "command": "${command:workbench.action.togglePanel}",
      "type": "shell",
      "problemMatcher": []
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

And you would run the "echo and hide" task which would run the task you really want first and then run the task with the command ${command:workbench.action.togglePanel} in it to hide the Panel (assuming that is where your Terminal is).

Unfortunately, what you can't do is this:

"command": "echo 'I have been hidden' && ${command:workbench.action.togglePanel}"

it doesn't seem to work.


Alternatively, look at the presentation properties:

    {
      "label": "simple echo",
      "command": "echo I have been hidden",
      "type": "shell",
      "problemMatcher": [],
      "presentation": {
        "echo": true,
        "reveal": "silent",    // <== open only on problems
        "focus": false,
        "panel": "shared",
        "showReuseMessage": true,
        "clear": false
      }
    }
Run Code Online (Sandbox Code Playgroud)

This will not open the Terminal if it is closed (unless there are problems with the task). But it will not hide a Terminal that is already open when you run the task. If you want the Terminal to always hide when you run a task you may have to look at the first option of dependent tasks.