Home > other >  How to configure VS Code to auto hide, not close, the Terminal panel after a task completes
How to configure VS Code to auto hide, not close, the Terminal panel after a task completes

Time:01-28

After a task completes, the terminal will stay open. Is there anyway to auto hide it?

I am not talking about closing the window as described at enter image description here

CodePudding user response:

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": []
    }
  ]
}

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

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.

  •  Tags:  
  • Related