Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of "Terminal will be reused by tasks, press any key to close it." behaviour?

Upon executing a task (cargo build in this case), the following appears in the VSCode terminal:

> Executing task: cargo build <  (output of the task here)  Terminal will be reused by tasks, press any key to close it. 

Annoyingly, this takes me out of the normal terminal and then I have to acquire focus of the terminal window and press a key to get back. And when I do so, the output of cargo build disappears.

How do I stop this behaviour?

How do I get rid of the first and last lines of text?

like image 520
A.B. Avatar asked Dec 22 '17 20:12

A.B.


People also ask

How do you stop a terminal from running in code?

Remove terminal instances by hovering a tab and selecting the Trash Can button, selecting a tab item and pressing Delete, using Terminal: Kill the Active Terminal Instance command, or via the right-click context menu. Navigate between terminal groups using focus next Ctrl+PageDown and focus previous Ctrl+PageUp.

How do I close all Vscode terminals?

There is a Terminal: Kill All Terminals command, not bound to anything by default. Or search for the command in your Keyboard Shortcuts page and click on the pencil icon to enter some keybinding.

What is task json in Vscode?

The tasks. json example above does not define a new task. It annotates the tsc: build tasks contributed by VS Code's TypeScript extension to be the default build task. You can now execute the TypeScript compiler by pressing Ctrl+Shift+B.

How do I run a task in Vscode?

Executing Commands This is done by entering the Command Palette (F1 or ctrl-shift-p), typing task and selecting Tasks: Configure Task Runner. This will create a tasks. json file under the . vscode directory in the current folder.


2 Answers

To be clear, executing a task will always create a new integrated terminal in VS Code. There is no way around that. The most important thing is for the original terminal to be displayed instead of the newly created integrated terminal. (We want the original terminal revealed.)

@Gregory Cosmo Haun's solution will suppress the message "Terminal will be reused by tasks, press any key to close it". However, it still reveals the new integrated terminal instead of the normal terminal. (so you still have to press "any key" to close that terminal and reveal the original terminal)

A better solution would be to set "reveal": "silent", which will still create a new integrated terminal, but not reveal it unless there is an error while executing your task. I also set "clear": true (which is optional) so that the terminal is cleared before executing the task. I deliberately omit "showReuseMessage": false (which is optional) but you can add it. Who cares if the prompt is suppressed or not? The most important thing is that the newly created terminal is not revealed so I don't have to "press any key" to close it.

"presentation": {   "reveal": "silent",   "clear": true } 

BTW, you can also set "reveal": "never", but you would normally want to see the error message if there is a problem with executing your task.

In my opinion, this is the best possible solution. Yes, a new integrated terminal will always be created when executing a task, but at least it won't be revealed (unless there is an error) and you can safely ignore it without having to press any key to close it.

like image 182
kimbaudi Avatar answered Sep 19 '22 10:09

kimbaudi


Check if the new feature from VSCode 1.57 (May 2021, 2.5 years after the OP) could help:

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",       "revealProblems": "onProblem",       "close": true   } } 

[EDIT: 18-08-2018] Making it switch into the Problems tab is better when using the close option as that ensures the task terminal is closed, but the problems are properly highlighted. This is from VSCode 1.59.0.

like image 44
VonC Avatar answered Sep 18 '22 10:09

VonC