How to automatically clear the VS Code terminal when starting the assembly?

I press Ctrl+ Shift+ Bto start the assembly of Visual Studio code (it is configured only to run GNU Make), and the output of the assembly tool is written in the terminal window.

However, it is added to the exit from the previous assembly, which is confusing.

How do I configure VS code to clear a terminal window before starting a new build?

+10
source share
4 answers

I tried to find a solution, but I can’t. A simple hack I tried to open a new assembly in a new tab. Add this key presentationto your task intasks.json

 "presentation": {
                "echo": true,
                "reveal": "never",
                "focus": false,
                "panel": "new"
            }
Panel

: A new one will be opened in the new terminal.

+4
source

2018

( ), clear , .

( + ):

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "[gcc] Build",
            "type": "shell",
            "command": "g++",
            "args": [
                "source.h",
                "-Wall",
                "-o",
                "a.out"
            ],
            "presentation": {
                "clear": true                        // <-- this line
            }
        }
    ]
}

(: clearBeforeExecuting , -, clear).

clear_g++ :

#!/bin/bash
clear
exec g++ $*

command g++ clear_g++.

, .

+2

, clear:

"tasks": [
    {
        "label": "build",
        "type": "shell",
        "command": "clear && make",
....
+1

Add this custom option to clear the EXIT tab when you click the Run button (▶)

"code-runner.clearPreviousOutput": true,

This is not the same as cleaning the terminal, but it may be what someone wants.

[Edit] This requires the Runner extension, which I would recommend for testing / running scripts directly in VS Code.

+1
source

All Articles