我按Ctrl+ Shift+在Visual Studio CodeB中开始构建(它被配置为只运行 GNU Make),构建工具输出被写入终端窗口。
但是,它被附加到先前构建的输出中,这令人困惑。
如何配置 VS Code 以在开始新构建之前清除终端窗口?
我按Ctrl+ Shift+在Visual Studio CodeB中开始构建(它被配置为只运行 GNU Make),构建工具输出被写入终端窗口。
但是,它被附加到先前构建的输出中,这令人困惑。
如何配置 VS Code 以在开始新构建之前清除终端窗口?
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++
.
因为我喜欢这种方法的想法,但最终没有成功。
我试图找到一个解决方案,但不能。我尝试的简单技巧是在新标签中打开新版本。将此presentation
密钥添加到您的任务中tasks.json
"presentation": {
"echo": true,
"reveal": "never",
"focus": false,
"panel": "new"
}
panel:new 将在新终端中打开。
添加此用户设置以在单击运行时清除 OUTPUT 选项卡 (▶)
"code-runner.clearPreviousOutput": true,
这与清除终端不同,但它可能是某人想要的。
[编辑] 这需要 Runner 扩展,我建议直接在 VS Code 中测试/运行脚本。
如果您自己控制构建任务,则很容易预先添加clear
命令:
"tasks": [
{
"label": "build",
"type": "shell",
"command": "clear && make",
....
在 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
}
}
]
}