如何在终端打印出有颜色的字
8-bit color
ESC[ 38;5;⟨n⟩ m Select foreground color
ESC[ 48;5;⟨n⟩ m Select background colorconst bg = 255;
const text = 'hello world';
// setting background
console.log(`\x1b[48;5;${i}m${text}`);
// reset setting
console.log(`\x1b[0m`);
// setting background and foreground
console.log(`\x1b[48;5;255m\x1b[38;5;222m${text}`);
24-bit color
Some color references
A simple chalk tool

more info
Last updated