admin管理员组文章数量:1419905
In this answer, the users describes in details how to color the text in the console when using node.js. The official documentation is even posted in a ment to the answer.
Unfortunately, this only shows us how to use 8 colors for the text, and the same 8 colors for the background. In practive, since any text will be invisible on the same background color, this means we can only use 7 colors unless we are willing to change the background often.
FgBlack = "\x1b[30m"
FgRed = "\x1b[31m"
FgGreen = "\x1b[32m"
FgYellow = "\x1b[33m"
FgBlue = "\x1b[34m"
FgMagenta = "\x1b[35m"
FgCyan = "\x1b[36m"
FgWhite = "\x1b[37m"
What I am looking for, is a way to get more colors for the console. It can be with an external module or library, can be official or not, etc.
Specifically, the colors Orange, Purple, Pink and Brown are very mon, and I assume that there is some way to get them.
Of course, the ideal situation would be some way to provide an RGB directly, so I can make my own shades of colors too, but I'll accept any answer that provides access to at least 4 more colors, because I need 11-12 at minimum for something I'm doing.
How can I get more colors for the console in Node.Js?
In this answer, the users describes in details how to color the text in the console when using node.js. The official documentation is even posted in a ment to the answer.
Unfortunately, this only shows us how to use 8 colors for the text, and the same 8 colors for the background. In practive, since any text will be invisible on the same background color, this means we can only use 7 colors unless we are willing to change the background often.
FgBlack = "\x1b[30m"
FgRed = "\x1b[31m"
FgGreen = "\x1b[32m"
FgYellow = "\x1b[33m"
FgBlue = "\x1b[34m"
FgMagenta = "\x1b[35m"
FgCyan = "\x1b[36m"
FgWhite = "\x1b[37m"
What I am looking for, is a way to get more colors for the console. It can be with an external module or library, can be official or not, etc.
Specifically, the colors Orange, Purple, Pink and Brown are very mon, and I assume that there is some way to get them.
Of course, the ideal situation would be some way to provide an RGB directly, so I can make my own shades of colors too, but I'll accept any answer that provides access to at least 4 more colors, because I need 11-12 at minimum for something I'm doing.
How can I get more colors for the console in Node.Js?
Share Improve this question edited Sep 6, 2018 at 12:53 Luca Kiebel 10.1k7 gold badges32 silver badges46 bronze badges asked Aug 31, 2018 at 17:28 Kaito KidKaito Kid 1,1135 gold badges17 silver badges38 bronze badges 4- Have you tried chalk? They (used to) support Truecolor – Luca Kiebel Commented Aug 31, 2018 at 17:33
- I just tried it and it works, why didn't you put this as an answer? It does exactly what I wanted :D – Kaito Kid Commented Sep 6, 2018 at 12:36
- I really thought we could have developed some sort of discussion on the topic here. Like you saying "No, but I'll try it now", and then I would've wrote an answer.... – Luca Kiebel Commented Sep 6, 2018 at 12:37
- Hope it's still relevant ;-) – Luca Kiebel Commented Sep 6, 2018 at 12:51
3 Answers
Reset to default 2You can use chalk for this:
First, make sure that you enable Truecolor for chalk, so that you can use all the colors you want to use:
const chalk = require("chalk"),
ctx = new chalk.constructor({level: 3}); // 3 for Truecolor: https://github./chalk/chalk#chalklevel
After that you can use the Extended Colors from CSS, like Orange, Purple, Pink and Brown:
console.log(ctx.keyword('orange')('Orange!'))
console.log(ctx.keyword('purple')('Purple!'))
console.log(ctx.keyword('pink')('Pink!'))
console.log(ctx.keyword('brown')('Brown
本文标签:
javascriptHow can I get more colors for nodejs consoleStack Overflow
版权声明:本文标题:javascript - How can I get more colors for node.js console - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1745315463a2653133.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论