vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

No colors in task terminal with clang

Open skarasov opened this issue 2 years ago • 4 comments

Issue Type: Bug

Simple c code. Run build task with clang or cl. In task terminal no colored output, but in ordinary terminal all fine. b

refer: https://github.com/microsoft/vscode/issues/155444

Extension version: 1.11.4 VS Code version: Code 1.69.2 (3b889b090b5ad5793f524b5d1d39fda662b96a2a, 2022-07-18T16:12:52.460Z) OS version: Windows_NT x64 10.0.19044 Restricted Mode: No

skarasov avatar Jul 26 '22 15:07 skarasov

The issue doesn't repro for me. What task type are you using in your task.json? Are you using arg " -fdiagnostics-color=always"?

sean-mcmanus avatar Jul 26 '22 17:07 sean-mcmanus

No color only with clang.exe and cl.exe. With gcc.exe all fine.

task.json:

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: clang.exe build active file",
			"command": "C:\\Program Files\\LLVM\\bin\\clang.exe",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${file}",
				"-o",
				"${fileDirname}\\${fileBasenameNoExtension}.exe"
			],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"isDefault": true,
				"kind": "build"
			},
			"detail": "compiler: \"C:\\Program Files\\LLVM\\bin\\clang.exe\""
		}
	]
}

skarasov avatar Jul 27 '22 11:07 skarasov

Hi @skarasov .

The root of this problem has to do with how gcc and clang detect whether or not they are running within a shell terminal. If they detect they are in a shell terminal, they enable colorization. We could consider it a VS Code bug that the terminal used for tasks does not look like a shell terminal to them. I suspect it has something to do with how VS Code is redirecting and scanning the output of the task, circumventing the compiler's check. We can work around this issue with gcc by forcing colorization to be enabled using -fdiagnostics-color=always.

After some experimentation, it looks like we can convince clang to also enable colorization using:

                "-fcolor-diagnostics",
                "-fansi-escape-codes",

We can use this issue to track adding these args to a task when the compiler used appears to be clang, instead of -fdiagnostics-color=always.

Colengms avatar Jul 27 '22 21:07 Colengms

                "-fcolor-diagnostics",
                "-fansi-escape-codes",

works for me, Thanks!

skarasov avatar Jul 31 '22 13:07 skarasov

Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.12.1 .

sean-mcmanus avatar Aug 16 '22 23:08 sean-mcmanus