Visual Studio Code Debug Console colors?

后端 未结 8 1561
旧巷少年郎
旧巷少年郎 2020-12-06 04:34

Is there a way to display colors (like in a terminal) in the Debug Console of Visual Studio Code (Version 1.10.2) when debugging node.js code?

8条回答
  •  无人及你
    2020-12-06 05:07

    To output coloured messages from nodejs in visual studio you can use formatted message in console.log method. for example :

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

    as implemented in Mocha. 32 is a color code. Other color codes and usage sample you can find in theirs repo: https://github.com/mochajs/mocha/blob/9e95d36e4b715380cef573014dec852bded3f8e1/lib/reporters/base.js#L48

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

提交回复
热议问题