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 ") + "\n" +
Chalk.red.bold("Long title. More than 2 words.") + "\n" +
Chalk.redBright("Description") + "\n"
);
console.log(
Chalk.bgYellow.bold(" Warning ") + " " + Chalk.bgYellowBright(" Short title ") + "\n" +
Chalk.yellow.bold("Long title. More than 2 words.") + "\n" +
Chalk.yellowBright("Description") + "\n"
);
console.log(
Chalk.bgGreen.bold(" Success ") + " " + Chalk.bgGreenBright(" Short title ") + "\n" +
Chalk.green.bold("Long title. More than 2 words.") + "\n" +
Chalk.greenBright("Description") + "\n"
);
console.log(
Chalk.bgBlue.bold(" Info ") + " " + Chalk.bgBlueBright(" Short title ") + "\n" +
Chalk.blue.bold("Long title. More than 2 words.") + "\n" +
Chalk.blueBright("Description") + "\n"
);
console.log(
Chalk.bgCyan.bold(" Info ") + " " + Chalk.bgCyanBright(" Short title ") + "\n" +
Chalk.cyan.bold("Long title. More than 2 words.") + "\n" +
Chalk.cyanBright("Description") + "\n"
);
console.log(
Chalk.bgMagenta.bold(" Info ") + " " + Chalk.bgMagentaBright(" Short title ") + "\n" +
Chalk.magenta.bold("Long title. More than 2 words.") + "\n" +
Chalk.magentaBright("Description") + "\n"
);
console.log(
Chalk.bgWhite.bold(" Info ") + " " + Chalk.bgWhiteBright(" Short title ") + "\n" +
Chalk.white.bold("Long title. More than 2 words.") + "\n" +
Chalk.whiteBright("Description") + "\n"
);
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 thanbg**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.