DEV Community

Valeria
Valeria

Posted on

Day 12: Pico-co-colors πŸ₯

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("!")
);
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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?

Buy Me A Coffee

Top comments (2)

Collapse
 
fyodorio profile image
Fyodor

When they say β€œno dependencies”, I’m sold πŸ₯³

Collapse
 
valeriavg profile image
Valeria

I know right?! I was gonna write about Chalk first, but this one is leaner πŸ€—