microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.48k stars 457 forks source link

Build task isn't colored in terminal #2783

Open serfreeman1337 opened 2 years ago

serfreeman1337 commented 2 years ago

Brief Issue Summary

I'm trying to get color output in terminal. Suggested workaround here https://github.com/microsoft/vscode-cmake-tools/issues/478#issuecomment-1081093372 isn't working as expected.

Compiler errors are only colored with set(CMAKE_CXX_FLAGS -fdiagnostics-color=always) is in CMakeList.txt, but "Building CXX Object" messages are still in white.

Switching task to shell command shows desired colored output ("Building CXX Object" messages are in green color):

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "CMake: build and run",
            "command": "cmake --build ${workspaceFolder}/build --config Debug --target ${workspaceFolderBasename} && ${workspaceFolder}/build/${workspaceFolderBasename}",
            "group": "build"
        }
    ]
}

CMake Tools Diagnostics

CMake: Log Diagnostics ```shell { "os": "linux", "vscodeVersion": "1.72.0", "cmtVersion": "1.12.27", "configurations": [ { "folder": "/home/serfreeman1337/Dev/tmp-esp32-cv-test", "cmakeVersion": "3.24.2", "configured": true, "generator": "Unix Makefiles", "usesPresets": false, "compilers": { "C": "/usr/bin/gcc", "CXX": "/usr/bin/g++" } } ], "cpptoolsIntegration": { "isReady": true, "hasCodeModel": true, "activeBuildType": "Debug", "buildTypesSeen": [ "Debug" ], "requests": [ "file:///home/serfreeman1337/Dev/tmp-esp32-cv-test/oh.cc", "file:///home/serfreeman1337/Dev/tmp-esp32-cv-test/tmp-esp32-cv-test.cc" ], "responses": [ { "uri": "file:///home/serfreeman1337/Dev/tmp-esp32-cv-test/oh.cc", "configuration": { "includePath": [ "/usr/include/opencv4" ], "defines": [], "compilerPath": "/usr/bin/g++", "compilerArgs": [], "compilerFragments": [ "-g", "-std=gnu++17" ] } }, { "uri": "file:///home/serfreeman1337/Dev/tmp-esp32-cv-test/tmp-esp32-cv-test.cc", "configuration": { "includePath": [ "/usr/include/opencv4" ], "defines": [], "compilerPath": "/usr/bin/g++", "compilerArgs": [], "compilerFragments": [ "-g", "-std=gnu++17" ] } } ], "partialMatches": [], "targetCount": 1, "executablesCount": 1, "librariesCount": 0, "targets": [ { "name": "tmp-esp32-cv-test", "type": "EXECUTABLE" } ] }, "settings": [ { "communicationMode": "automatic", "useCMakePresets": "auto", "configureOnOpen": true } ] } ```

Debug Log

No response

Additional Information

Screenshots Workaroud with `set(CMAKE_CXX_FLAGS -fdiagnostics-color=always)`: ![image](https://user-images.githubusercontent.com/2133936/194719375-db38e4ec-73f6-48f5-812b-ce5631103632.png) Task as shell command without `fdiagnostics-color` flag: ![image](https://user-images.githubusercontent.com/2133936/194719384-f4b230d0-496d-4f93-a220-a600962c3d2e.png)
bobbrow commented 2 years ago

It seems that the way we are doing tasks removes the colors. Right now, if we were to send the commands directly to the terminal, we could get colors, but we also wouldn't be able to tell when the build completed or whether it succeeds or not. We'll need to talk to the VS Code team to see if they can give us more information from the Terminal object.

piomis commented 2 years ago

On my ArmClang, Windows 10 and VSCode Cmake Tools it looks to be working (I have it configured to useBuildTask) . When I add compiler setting: -fdiagnostics-color=always it looks to be working when ArmClang called directly from shell. But not if I build with ninja and/or cmake (thus also VSCode CMake tools).

But when I add -fansi-escape-codes as compiler option it starts to be working also with ninja, cmake and in vscode termianal output.

image

Obviously these are only Clang colours. Ninja messages are still monochromatic. As far as I managed to find out it is more ninja limitation which automatically disables colours when detecting to be called in "piped" way (and that is how cmake runs ninja).

bobbrow commented 2 years ago

I'm talking with the VS Code team about this issue: https://github.com/microsoft/vscode/issues/145234. If we can move the implementation to run directly in the terminal, I think it will work the way you expect.

moefear85 commented 12 months ago

for those waiting for salvation: vscode extensions->build output colorizer by steve bush.

starball5 commented 9 months ago

@piomis yes. see Ninja Build System + gcc/clang doesn't output diagnostic colors

Also, more generally, How can I configure CMake to generate a buildsystem that emits colored errors and warnings?