GitHub
Skip to content

Progress

How out.progress and createProgress show a long step: a live bar on a terminal, a line every 5 seconds in CI and pipes, nothing for agents or JSON.

out.progress(label) shows that a long step is alive, and decides per reader what that looks like. Progress goes to stderr only, so it never mixes with the answer on stdout.

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

update({ done, total, doneBytes?, totalBytes? }) reports how far the step got. stop() ends it and clears the line on a terminal. Both do nothing after stop(), and stop() is safe to call twice.

What each reader gets:

ReaderFormatProgress on stderr
TerminaltextOne line with a bar, rewritten in place
CI, pipetextA plain line every 5 seconds
Anytext with --quietNothing
Coding agentagentNothing
Anyjson, jsonlNothing

Off text, update and stop do nothing, so the command calls them the same way for every reader.

Nothing prints for the first 2 seconds. A step that finishes sooner shows no progress at all. If no update came by then, the label prints alone.

On a terminal, readerly redraws the line at most every 100 ms. With done: 100 of 400 after 2.5 seconds, it reads:

Scanning files  ████████░░░░░░░░░░░░░░░░░░░░░░  25%  ~8s left
text

The bar is up to 30 cells wide. Below 10 cells, the line drops the bar, then shortens the label. The time left appears once a second has passed since the first update and done has grown.

Off a terminal, a line prints every 5 seconds at most, with the counts. The loop above, over 400 files at 25 ms each, prints in CI:

Scanning files: 80 of 400 files, 20%, ~8s left
Scanning files: 280 of 400 files, 70%, ~3s left
text

With totalBytes, the share and the time left follow doneBytes instead of done. A download with 1 of 3 files done and 120 MB of 300 MB shows 40%.

createProgress(label, options) from readerly/progress is the same line without createOut. It always prints, so you decide when to call it. Its options:

OptionDefaultMeaning
stderrprocess.stderrWhere the line goes. isTTY picks the bar or the plain line.
nowDate.nowThe clock, in milliseconds.
shortLabellabelThe label for a terminal too narrow for label.
intrononeA line printed once before the first progress line, off a terminal only.
unitfilesWhat done and total count, in the plain line.

out.progress passes its io.stderr and io.now, so a fake Io controls the clock in tests.