We've already touched gradients in the terminal, but what if you'd like to simply color one line, word or phrase? Well, picocolors does exactly that nice and easy!
Install with your favourite package manager, e.g. deno add npm:picocolors
and create a file, e.g. main.ts
:
import pico from "picocolors";
console.log(
pico.redBright("Happy ") +
pico.greenBright("Holidays") +
pico.yellowBright("!")
);
Run with e.g. deno run -A ./main.ts
and enjoy the festive greeting:
Of course, you could always use ASCII Color codes directly, e.g. like so:
console.log(
"\u001b[91mHappy \u001b[92mHolidays\u001b[93m!"
); // 91 = Foreground bright red, 92 = Bright green and 93 is Bright yellow
But that's way less descriptive, isn't it?
Not to mention that picocolors
is NO_COLOR
friendly and comes with couple of extra beauties like italic
, bold
, dim
and inverse
.
Do try them out and share your creations!
Liked the content and would love to have more of it all year long?
Top comments (2)
When they say βno dependenciesβ, Iβm sold π₯³
I know right?! I was gonna write about Chalk first, but this one is leaner π€