In the Chalk documentation, there is just allusion that this library will not work properly in Windows:
If you're on Windows, do yourself a favor and use Windows Terminal
instead of cmd.exe.
IMHO it's not acceptable because the basic tool of modern development is IDE with own terminal, so the terminal highlight library must not depend on specific terminal.
From here, we have at least three questions:
- Why Chalk can not correctly output the font/background color?
- How to output background or font color in any terminal as specified?
- If Chalk can't do it, which Node.js utilities can?
I know I can't ask all of above in single question, so current topic is focused on why Chalk can't output colors as specified.
console.log(
Chalk.bgRed.bold(" Error ") + " " + Chalk.bgRedBright(" Short title ") + "
" +
Chalk.red.bold("Long title. More than 2 words.") + "
" +
Chalk.redBright("Description") + "
"
);
console.log(
Chalk.bgYellow.bold(" Warning ") + " " + Chalk.bgYellowBright(" Short title ") + "
" +
Chalk.yellow.bold("Long title. More than 2 words.") + "
" +
Chalk.yellowBright("Description") + "
"
);
console.log(
Chalk.bgGreen.bold(" Success ") + " " + Chalk.bgGreenBright(" Short title ") + "
" +
Chalk.green.bold("Long title. More than 2 words.") + "
" +
Chalk.greenBright("Description") + "
"
);
console.log(
Chalk.bgBlue.bold(" Info ") + " " + Chalk.bgBlueBright(" Short title ") + "
" +
Chalk.blue.bold("Long title. More than 2 words.") + "
" +
Chalk.blueBright("Description") + "
"
);
console.log(
Chalk.bgCyan.bold(" Info ") + " " + Chalk.bgCyanBright(" Short title ") + "
" +
Chalk.cyan.bold("Long title. More than 2 words.") + "
" +
Chalk.cyanBright("Description") + "
"
);
console.log(
Chalk.bgMagenta.bold(" Info ") + " " + Chalk.bgMagentaBright(" Short title ") + "
" +
Chalk.magenta.bold("Long title. More than 2 words.") + "
" +
Chalk.magentaBright("Description") + "
"
);
console.log(
Chalk.bgWhite.bold(" Info ") + " " + Chalk.bgWhiteBright(" Short title ") + "
" +
Chalk.white.bold("Long title. More than 2 words.") + "
" +
Chalk.whiteBright("Description") + "
"
);
IntellIJ IDEA, Monokai color theme:
- For each
cosole.log()
, "Long title. More than 2 words." and "Description" has same color.
- Some
bg**
s are brighter than bg**Bright
!
- All
bold
s except white has been ignored.
- The font color has been set automatically where background color defined. I did not ask this, and also sometimes the font is almost unreadable.
Cmder
A little bit better, but most of problems left.
Default Windows terminal
Not so bad in the comparison with above ones.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…