Day 12: Pico-co-colors 🐥
Valeria

Valeria @valeriavg

About: Re-inventor extraordinaire, optimisation addict and open web advocate.

Location:
Stockholm, Sweden
Joined:
Sep 23, 2020

Day 12: Pico-co-colors 🐥

Publish Date: Dec 12 '24
4 3

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

Comments 3 total

Add comment