DEV Community

Cover image for Day 21: In the name of Progress! πŸ“ˆ
Valeria
Valeria

Posted on

2

Day 21: In the name of Progress! πŸ“ˆ

Patience is a virtue and it's much easier to stay patient when you see progress, isn't it? Today I'd like to share with you a library called cli-progress that does exactly that.

Let's install it with e.g. deno add npm:cli-progress and use in a script, e.g. main.ts:

import { SingleBar, Presets } from "cli-progress";
import { scheduler } from "node:timers/promises";

const bar = new SingleBar({}, Presets.shades_classic);

bar.start(5, 0);

for (let i = 0; i < 5; i++) {
  await scheduler.wait(1000);
  bar.update(i + 1);
}

bar.stop();
Enter fullscreen mode Exit fullscreen mode

Run it with e.g. deno run -A ./main.ts and enjoy an informative progress bar:

Progress bar

The library has plenty of other interesting options: e.g. you can customise format, symbols and much more.

Try out this code:

import { Bar } from "cli-progress";
import { scheduler } from "node:timers/promises";

const bar = new Bar({
  barCompleteChar: ":",
  barIncompleteChar: ".",
  fps: 5,
  barsize: 30,
  position: "center",
  format: "[{bar}] {percentage}% | ETA: {eta}s | {value}s/{total}s",
});

bar.start(5, 0);

for (let i = 0; i < 5; i++) {
  await scheduler.wait(1000);
  bar.update(i + 1);
}

bar.stop();
Enter fullscreen mode Exit fullscreen mode

Here's what it results in:

Progress bar with specified parameters

Liked the content and would love to have more of it all year long?

Buy Me A Coffee

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

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

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Communityβ€”every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple β€œthank you” goes a long wayβ€”express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay