Visual Studio Code Debug Console colors?

Is there a way to display colors (for example in terminal) in the Debug console of Visual Studio Code (version 1.10.2) when debugging node.js code?

+6


source to share


4 answers


I think so far the best way is to put the debug output in alternate destinations:

In the "Launch Configuration Attributes" section, the parameter console

can be set to one of the following values: internalConsole

(default - built-in debug console) externalTerminal

(external cmd window) or integratedTerminal

terminal (VS Code terminal).



Command line external terminal may be further contains a code VS settings under one of the following: terminal.external.windowsExec

, terminal.external.osxExec

and terminal.external.linuxExec

default terminal which is your default os.

Source: VS Documentation code, for example for node.js: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-attributes

+5


source


For best results, do not open the console either. Here is my config for debugging the current file using Jest:



{
    "type": "node",
    "request": "launch",
    "name": "Jest Test (current)",
    "program": "${workspaceFolder}/node_modules/.bin/jest",
    "args": [
        "--config=jest.config.json",
        "--runInBand",
        "${relativeFile}",
    ],
    // The vscode console does not support colors used by Jest output
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen",
}

      

+2


source


For outputting colored messages from nodejs in visual studio, you can use formatted message in console.log method. eg:

console.log('\u001b[' + 32 + 'm' + 'hello stack' + '\u001b[0m')

      

as implemented in mocha . 32 is the color code You can find more color codes and an example of use in their repository: https://github.com/mochajs/mocha/blob/9e95d36e4b715380cef573014dec852bded3f8e1/lib/reporters/base.js#L48

enter image description here

Or as a log library, you can use, for example, the pinojs + pino-pretty module , and your log output will be displayed like this:

enter image description here

0


source


My settings, color steps:

{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

    {
        "type": "node",
        "request": "launch",
        "console": "integratedTerminal",
        "name": "Cucumber",
        "program": "${workspaceFolder}/tests/cucumberjs/node_modules/cucumber/bin/cucumber-js",
        "cwd": "${workspaceFolder}/tests/cucumberjs",
        "args": [
            "--tags=@luke",
            "--format=node_modules/cucumber-pretty"
        ],
        "outputCapture": "std"
    }
]

      

}

0


source







All Articles