Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorized CMake/Build output #478

Open
Flamefire opened this issue Jul 13, 2018 · 49 comments
Open

Colorized CMake/Build output #478

Flamefire opened this issue Jul 13, 2018 · 49 comments
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: build help wanted we currently are not planning work on this and would like help from the open source community
Milestone

Comments

@Flamefire
Copy link

Executing CMake or the build command in a terminal shows it nicely formated with bold and colors. Is there anything that this extension can do to support this? Currently all output goes to the output pane which shows just Black&White output which makes it hard to read.

I've seen that task output is redirected to the terminal pane which does support coloring (since a bit ago), could this extension support this too? Or is there another option?

This might also be worth noting in the FAQ.

@vector-of-bool
Copy link
Contributor

The output channel gives no coloring options, so that's not going to work. A terminal supports ANSII, so that's the only way to do it at the moment. Running the build as a VSCode Task has proven difficult, but may be possible. There's a pending ext API in VSCode to have "custom terminals" where an ext can write bytes directly to a terminal window. That will probably be the route I go with in the future, but it's an open question.

@vector-of-bool vector-of-bool added the enhancement an enhancement to the product that is either not present or an improvement to an existing feature label Jul 13, 2018
@vector-of-bool vector-of-bool added this to the Backlog milestone Jul 13, 2018
@mika-fischer
Copy link

Any news on this? I use a task like this as a workaround:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "process",
            "command": "ninja",
            "options": {
                "cwd": "${workspaceRoot}/build"
            },
            "group": {
                "kind": "build",
                "isDefault": true,
            },
            "problemMatcher": [
                {
                    "base": "$gcc",
                    "fileLocation": ["relative", "${workspaceRoot}/build"]
                },
            ],
            "promptOnClose": true
        }
    ]
}

@bobbrow
Copy link
Member

bobbrow commented Sep 25, 2019

Sorry, no update yet. When this task is assigned a Milestone with a product version number, you will know that we are working on it.

@mika-fischer
Copy link

I was also asking if there's a clearer way forward than indicated in the last comment. But it seems there's not. The relevant vscode isssue is microsoft/vscode#571. See also #119 (comment).

However, I found that a better workaround is to just install the Output Colorizer extension and things just work for me: https://marketplace.visualstudio.com/items?itemName=IBM.output-colorizer

@nunojsa
Copy link

nunojsa commented Nov 18, 2019

This would be a really nice thing to add. Right now, I just prefer to do ctrl + j , go to the terminal and just type make manually to have the colorized build...

@Lectem
Copy link

Lectem commented Jan 9, 2020

I also miss this a lot, but more because of CTest.
Colors in the CTest output are invaluable for quick iterations !

@nunojsa
Copy link

nunojsa commented Jan 9, 2020

For me, the Output Colorizer plugin from IBM is working pretty good. You might give it a try. Never tried it with CTest though...

@Lectem
Copy link

Lectem commented Jan 9, 2020 via email

@dbird137
Copy link
Contributor

This isn't a general solution for just running CMake builds but if you're writing your own cmake scripts, I've had good luck with peppering these into my message() functions:

# Colorized Output Setup
if(NOT WIN32)
  string(ASCII 27 Esc)
  set(Reset 		"${Esc}[m")
  set(Bold  		"${Esc}[1m")
  set(Red         	"${Esc}[31m")
  set(Green       	"${Esc}[32m")
  set(Blue        	"${Esc}[34m")
  set(Cyan        	"${Esc}[36m")
  set(Magenta     	"${Esc}[35m")
  set(Yellow      	"${Esc}[33m")
  set(White       	"${Esc}[37m")
  set(BoldRed     	"${Esc}[1;31m")
  set(BoldGreen   	"${Esc}[1;32m")
  set(BoldBlue    	"${Esc}[1;34m")
  set(BoldCyan    	"${Esc}[1;36m")
  set(BoldMagenta 	"${Esc}[1;35m")
  set(BoldYellow  	"${Esc}[1;33m")
  set(BoldWhite   	"${Esc}[1;37m")
endif()

Then just use them like so...

message(STATUS "${Cyan} Here's some status...${Reset}")
message(DEBUG "${BoldYellow} Debugging some nonsense...${Reset}")
message(ERROR "${BoldRed} I hope you like Bach because your script is Baroque...${Reset}")

I've only tested this on xterm-256color.

FYI: The colors do carry over between messages because you're actually manipulating the terminal. So always do the ${Reset}.

@intractabilis
Copy link

Another issue with having the build output in "output" is that the errors are not clickable.

@timo-suoranta-varjo
Copy link

Another issue with having the build output in "output" is that the errors are not clickable.

This is caused by relative paths. You can workaround this by setting "cmake.buildDirectory": "${workspaceFolder}/../build" in your workspace settings.json.

@mohamedAlaaK
Copy link

can we run the build command inside a terminal or have an option for that? the run button already does that and it would be cool to have the build button does that too for the output to be colorized.

@daeden
Copy link

daeden commented Oct 26, 2021

Any update on this? I really miss seeing some color when building.

@andreeis
Copy link
Contributor

@daeden, unfortunately we were not able to get to this feature yet. If anyone is willing to implement this request, we are willing to review and test a PR.

@mohamedAlaaK
Copy link

@andreeis, How about having an option to run the build command inside the terminal instead of the output window? That should be easy to do.

@HunterZ
Copy link

HunterZ commented Mar 11, 2022

Just noticed this issue myself when running vscode from inside of an MSYS2 MinGW64 environment. Awkward!
image

The extensions "Output Colorizer" and "Janky Output Channels" both colorize the output, but leave the escape sequences in place, which I guess is better than nothing?

Edit: I'm not sure those extensions are actually parsing the ANSI sequences, versus just applying their own coloring heuristics?

@bobbrow
Copy link
Member

bobbrow commented Mar 11, 2022

You should be able to work around this by using the "cmake.buildTask": true setting to enable building in the terminal if you configure a default build task in .vscode/tasks.json. Something like this:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build the active target",
            "type": "cmake",
            "command": "build",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

@HunterZ
Copy link

HunterZ commented Mar 12, 2022

You should be able to work around this by using the "cmake.buildTask": true setting to enable building in the terminal if you configure a default build task in .vscode/tasks.json. Something like this:

While this does appear to accomplish redirection of output to a terminal tab, testing shows that it comes at a great cost:

  • Breaks the ability to do a clean
  • Breaks GCC warnings/errors being added to the "problems" tab
  • Breaks hyperlinking of filenames mentioned in the GCC output

@intractabilis
Copy link

I understand that this is not for everyone, but I switched to Meson plus xPack (https://marketplace.visualstudio.com/items?itemName=ilg-vscode.xpack). I never regretted this choice. I have color output for builds and hyperlinked error and warning messages. For IntelliSense I use compile_commands.json that Meson generates. I don't miss a single feature of CMake tools.

@bobbrow
Copy link
Member

bobbrow commented Mar 12, 2022

  • Breaks the ability to do a clean
  • Breaks GCC warnings/errors being added to the "problems" tab
  • Breaks hyperlinking of filenames mentioned in the GCC output

For the problems, you can add a "problemMatcher" to the task definition. "$gcc" and "$msbuild" are valid pre-defined matchers, or you can go custom: example from the docs.

The hyperlinking issue should also be addressed by configuring a problem matcher.

Are you saying none of the "CMake: Clean" commands work when you use this setting?

@HunterZ
Copy link

HunterZ commented Mar 12, 2022

Are you saying none of the "CMake: Clean" commands work when you use this setting?

Yes: Specifically, when I click "Clean All Projects" it acts as if I had instead clicked "Build All Projects" (invokes cmake with target all instead of clean). This was particularly obvious when testing, due to the fact that I had a bug in my code that was triggering a compiler error lol

"Clean Rebuild All Projects" seems to work fine.

@HunterZ
Copy link

HunterZ commented Mar 17, 2022

I should mention that vscode developers have stated unequivocally that they will not add support for colors to the Output window, because reasons: microsoft/vscode#141556 (comment)

They have directed people to file issues against extensions, so here we are.

@IGR2014
Copy link

IGR2014 commented Mar 21, 2022

Here is "Output window". All we want is just a support to ANSI colors! Thanks

image

@bobbrow
Copy link
Member

bobbrow commented Mar 28, 2022

A potential workaround for this is using "cmake.buildTask": true setting which will run the default build task for you in the terminal instead of having output go to the Output window. We are working on adding more options for this task provider in 1.11.

Use a tasks.json similar to this:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build the active target",
            "type": "cmake",
            "command": "build",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

@ehsanecc
Copy link

adding

    ...
    "cmake.buildTask": true,
    "cmake.environment": {
        "CLICOLOR_FORCE": "1"
    }

to settings.json make it colorful

@gcampbell-msft gcampbell-msft removed their assignment Oct 24, 2023
@github-project-automation github-project-automation bot moved this to Triage Needed in CMake Tools Nov 29, 2023
@gcampbell-msft gcampbell-msft moved this from Triage Needed to Pending Prioritization in CMake Tools Nov 29, 2023
@gcampbell-msft gcampbell-msft modified the milestones: 1.17, On Deck Nov 29, 2023
@moefear85
Copy link

this is really vscode's fault. they are clearly aware that people want ansci escape sequence support in the output tab.

@moefear85
Copy link

SOLVED

@lesterlo
Copy link

lesterlo commented Dec 7, 2023

adding

    ...
    "cmake.buildTask": true,
    "cmake.environment": {
        "CLICOLOR_FORCE": "1"
    }

to settings.json make it colorful

"cmake.buildTask": true is indeed able to show the color of CMake since it uses the terminal tab instead of the Output Tab for compilation. However, you will lose the feature of the Visual Studio Code C/C++ extension that displays warnings/errors on the editor line by line.

@touraill-adobe
Copy link

It seems the output channel can now be created with a language id, so that syntax gets highlighted; how about creating the channel with the ansi id from the ANSI Colors extension, or adding a setting so that users can set their own language id?

@ghost
Copy link

ghost commented Feb 11, 2024

@intractabilis
Copy link

I am genuinely puzzled. This issue is six years old. It exemplifies the principle that "there are no problems we can't create for ourselves." CMake Tools is an utterly useless extension. Guys, you are struggling with problems that wouldn't have existed in the first place if you hadn't used CMake Tools. All you need is a couple of lines in your tasks.json, then the output to console will be colorized and clickable. If you want CMake's language support (with auto-completion, syntax highlight, help tooltips, etc.), install the CMake Language Support extension without CMake Tools. Everything will work perfectly; you will have the bells, whistles, and colorized build output.

@ghost
Copy link

ghost commented Feb 11, 2024

I am genuinely puzzled. This issue is six years old. It exemplifies the principle that "there are no problems we can't create for ourselves." CMake Tools is an utterly useless extension. Guys, you are struggling with problems that wouldn't have existed in the first place if you hadn't used CMake Tools. All you need is a couple of lines in your tasks.json, then the output to console will be colorized and clickable. If you want CMake's language support (with auto-completion, syntax highlight, help tooltips, etc.), install the CMake Language Support extension without CMake Tools. Everything will work perfectly; you will have the bells, whistles, and colorized build output.

Thanks a lot for this ^^, maybe the extension has some usefulness it is much more than syntax support and colored outputs ^^, CMake Tools currently improves the intellisense and debugging a lot ^^, it is not perfect, but better than nothing ^^, IBM's Colorized Output extensions improves the coloring situation a bit ^^

@intractabilis
Copy link

IntelliSense is from the CMake Language Support extension. It works perfectly without CMake Tools. You are right about debugging, though; I forgot that they added a CMake debugger to CMake Tools. It works with CMake 3.27 or newer. Besides this, everything can be achieved with the tools already present in VS Code.

@ghost
Copy link

ghost commented Feb 11, 2024

IntelliSense is from the CMake Language Support extension. It works perfectly without CMake Tools. You are right about debugging, though; I forgot that they added a CMake debugger to CMake Tools. It works with CMake 3.27 or newer. Besides this, everything can be achieved with the tools already present in VS Code.

Great to know, VSCode isn't perfect and indeed tried to switch multiple times, I might try to make a better CMake C++ centered IDE soon, hopefully

@Lioncky
Copy link

Lioncky commented Feb 21, 2024

@iyadahmed

no need to set {"cmake.buildTask": true,}
install this and config like
image, you'll be happy get both of them.

    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope" : "markup.other.log.error",
                "settings": { "foreground": "#FF0000" , "fontStyle": "italic" }
            },
            {
                "scope" : "markup.other.log.warn",
                "settings": { "foreground": "#F08000", "fontStyle": "italic"  }
            },
            {
                "scope" : "markup.other.log.info",
                "settings": { "foreground": "#2cd3c5" }
            },
            {
                "scope" : "markup.other.log.debug",
                "settings": { "foreground": "#888585" }
            },
            {
                "scope" : "markup.other.log.highlight",
                "settings": { "foreground": "#19ff04" }
            },
            {
                "scope" : "markup.other",
                "settings": { "fontStyle": "italic" }
            },
            {
                "scope" : "markup.italic",
                "settings": { "fontStyle": "italic" }
            }
        ]
    },

@ghost
Copy link

ghost commented Feb 21, 2024

@iyadahmed

no need to set {"cmake.buildTask": true,} install this and config like image, you'll be happy get both of them.

    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope" : "markup.other.log.error",
                "settings": { "foreground": "#FF0000" , "fontStyle": "italic" }
            },
            {
                "scope" : "markup.other.log.warn",
                "settings": { "foreground": "#F08000", "fontStyle": "italic"  }
            },
            {
                "scope" : "markup.other.log.info",
                "settings": { "foreground": "#2cd3c5" }
            },
            {
                "scope" : "markup.other.log.debug",
                "settings": { "foreground": "#888585" }
            },
            {
                "scope" : "markup.other.log.highlight",
                "settings": { "foreground": "#19ff04" }
            },
            {
                "scope" : "markup.other",
                "settings": { "fontStyle": "italic" }
            },
            {
                "scope" : "markup.italic",
                "settings": { "fontStyle": "italic" }
            }
        ]
    },

thanks!

@7R35C0
Copy link

7R35C0 commented Apr 8, 2024

For a CMake function template, I made a module/function to print colored messages.

More information here: https://github.com/7R35C0/cmake-function-template.git

@gcampbell-msft
Copy link
Collaborator

Some updates on investigation I've done are located here #3683

@gcampbell-msft
Copy link
Collaborator

Just refreshing here to remind of the context and learnings we made in #3683

@stlfatboy
Copy link

stlfatboy commented Sep 23, 2024

still having this issue on vscode 1.93.1 with cmake 3.30.3 + cmake tool 1.19.52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: build help wanted we currently are not planning work on this and would like help from the open source community
Projects
Status: Pending Prioritization
Development

No branches or pull requests