GitHub
Skip to content

Progress

A progress line on stderr for a step that takes more than two seconds.
const scan = out.progress("Scanning files");
for (const [index, file] of files.entries()) {
  await lint(file);
  scan.update({ done: index + 1, total: files.length });
}
scan.stop();
ts

Nothing shows for a step that ends within two seconds. After that, progress goes to stderr, so stdout stays the answer.

Terminal
Scanning files  ██████████████████░░░░░░░░░░░░  60%  ~4s left
txt
CI or a pipe
Scanning files: 128 of 212 files, 60%, ~4s left
txt

At a terminal it is one line, rewritten in place and cleared on stop(). Off a terminal, a new line every five seconds. Agents, --format json, --format jsonl and --quiet get no progress.

scan.update({ done: 3, total: 10, doneBytes: 120_000_000, totalBytes: 400_000_000 });
ts

With bytes, the share and the time left follow the bytes.

import { createProgress } from "readerly/progress";

const bar = createProgress("Downloading", { unit: "packages", shortLabel: "Dl" });
ts

createProgress takes the stream, the clock, a shortLabel for a narrow terminal, an intro line printed once off a terminal, and the unit its lines count, files by default.