DEV Community

Valeria
Valeria

Posted on

4

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (3)

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 🤗

Collapse
 
webdiscus profile image
webdiscus

please pay attention to ansis.

There is the list of similar libraries:

chalk,
picocolors,
kleur,
ansi-colors,
kolorist,
colorette,
cli-color,
colors-cli,
colors.js,

You can compare features and benchmarks of all libraries from the list above.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay