开始构建时如何自动清除 VS Code 终端? [英] How do I automatically clear VS Code terminal when starting a build?

查看:47
本文介绍了开始构建时如何自动清除 VS Code 终端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按 Ctrl+Shift+BVisual Studio Code 中开始构建(它被配置为只需运行 GNU Make),构建工具的输出就会写入终端窗口.

I press Ctrl+Shift+B to start a build in Visual Studio Code (it's configured to just run GNU Make), and the build tool output is written to the Terminal window.

然而,它被附加到先前构建的输出中,这令人困惑.

However, it's appended to the output from the previous build, which is confusing.

如何在开始新构建之前配置 VS Code 以清除终端窗口?

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

推荐答案

2018 年 11 月更新

截至本次提交(以及一些后续的跟进),您可以现在为您的任务添加一个 clear 演示选项,以便在每个任务运行之前清除终端.

As of this commit (and a few subsequent follow-ups), you can now add a clear presentation option to your task to have it clear the terminal before each task run.

工作示例(在新的克隆+构建上):

Working example (on fresh clone+build):

{
    // 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).

(Note: the linked commit diff has the key being named clearBeforeExecuting but it's apparently since been changed to just clear).

在此之前,我在我的路径上创建了一个 clear_g++ 脚本:

Prior to this, I created a clear_g++ script on my path with just:

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

并将我的 commandg++ 更改为 clear_g++.

And changed my command from g++ to clear_g++.

因为我喜欢这种方法的想法,但最终没有成功.

Since I liked the idea of this approach but it didn't end up working out.

这篇关于开始构建时如何自动清除 VS Code 终端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆