48

我按Ctrl+ Shift+在Visual Studio CodeB中开始构建(它被配置为只运行 GNU Make),构建工具输出被写入终端窗口。

但是,它被附加到先前构建的输出中,这令人困惑。

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

4

8 回答 8

52

2018 年 11 月更新

本次提交(以及随后的一些后续行动)中,您现在可以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但显然它已更改为 just clear)。

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

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

并将我command的从更改g++clear_g++.

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

于 2018-11-06T21:13:41.230 回答
15

您可以从设置菜单更改(至少从版本 1.30.2 及更高版本)...

在 Mac 上,只需点击代码 > 首选项 > 设置。

然后只需搜索“清除”并检查清除以前的输出。

从菜单设置中清除上一个输出

于 2019-02-03T23:18:06.040 回答
7

我试图找到一个解决方案,但不能。我尝试的简单技巧是在新标签中打开新版本。将此presentation密钥添加到您的任务中tasks.json

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

panel:new 将在新终端中打开。

于 2017-09-14T14:28:27.110 回答
6

添加此用户设置以在单击运行时清除 OUTPUT 选项卡 (▶)

"code-runner.clearPreviousOutput": true,

这与清除终端不同,但它可能是某人想要的。

[编辑] 这需要 Runner 扩展,我建议直接在 VS Code 中测试/运行脚本。

于 2018-08-15T05:38:41.013 回答
1

更新视觉代码 1.54 +

单击运行时清理终端。

  1. 安装代码运行器扩展。
  2. 设置>搜索“清除”->选中“清除上一个输出” 在此处输入图像描述 在此处输入图像描述
于 2021-03-14T04:02:06.817 回答
1

如果您自己控制构建任务,则很容易预先添加clear命令:

"tasks": [
    {
        "label": "build",
        "type": "shell",
        "command": "clear && make",
....
于 2018-07-25T07:17:05.957 回答
1

新的 Visual Studio 代码 1.56。这适用于 Windows。

您只需转到首选项:打开设置(UI),搜索“清除”并检查选项如下:

在此处输入图像描述

这将确保终端在每次运行时都保持清晰,从而确保一次只有一个文件运行可见。

于 2021-05-27T01:02:38.910 回答
0

在 Visual Studio Code 1.52.1 版本中,终端的默认清空是通过clear: true属性实现的(=控制在执行任务之前是否清空终端。)。不幸的是,它不起作用,我仍然看到终端显示旧消息。我必须在终端中手动输入“清除”才能完全清除它。

"presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": true
            }

这是在 OSX 下的 tasks.json 中添加的:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-std=c++11",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: /usr/bin/clang++",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": true
            }
        }
    ]
}
于 2021-02-08T01:17:32.697 回答