我按下 Ctrl+Shift+B 在 Visual Studio Code 中开始构建(配置为运行 GNU Make),构建工具输出到终端窗口。
但是,它会追加到上一次构建的输出中,这很令人困惑。
如何配置 VS Code 在开始新的构建之前清空终端窗口?
我按下 Ctrl+Shift+B 在 Visual Studio Code 中开始构建(配置为运行 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
,但显然已经更改为clear
。
在此之前,我在我的路径上创建了一个clear_g++
脚本,其中只包含:
#!/bin/bash
clear
exec g++ $*
然后我将我的command
从g++
改为clear_g++
。
因为我喜欢这种方法的想法,但最终它并没有奏效。
在点击运行(▶)时,添加此用户设置以清除“输出”选项卡。
"code-runner.clearPreviousOutput": true,
这并不是清除终端的同义词,但可能是某些人想要的。
[编辑] 这需要Runner扩展,我建议在VS Code中直接测试/运行脚本时使用。
"code-runner.clearPreviousOutput": true
选项,VS 识别了它。然后我按了几次 Ctrl+Shift+B,但输出并没有被清除。 - Mikhail我试图找到解决方案,但是无法找到。我尝试的简单方法是在新标签页中打开新构建。在tasks.json
中,在您的任务中添加presentation
键。
"presentation": {
"echo": true,
"reveal": "never",
"focus": false,
"panel": "new"
}
面板:新的将在新的终端中打开。
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
}
{
"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
}
}
]
}
clear
命令很容易:"tasks": [
{
"label": "build",
"type": "shell",
"command": "clear && make",
....
/bin/bash: clear && g++: command not found
//
终端进程以退出代码127终止
- jedwardsclear
和 make
命令。我认为当从存在这些命令的 shell 启动时,它会起作用。 - xtofl[
{
"key": "f5",
"command": "runCommands",
"args": {
"commands": [
"workbench.output.action.clearOutput",
"testing.refreshTests",
"cmake.ctest"
]
}
}
]