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.
out.progress
Section titled "out.progress"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();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:
| Reader | Format | Progress on stderr |
|---|---|---|
| Terminal | text | One line with a bar, rewritten in place |
| CI, pipe | text | A plain line every 5 seconds |
| Any | text with --quiet | Nothing |
| Coding agent | agent | Nothing |
| Any | json, jsonl | Nothing |
Off text, update and stop do nothing, so the command calls them the same way for every reader.
The 2-second rule
Section titled "The 2-second rule"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 leftThe 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 leftWith 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
Section titled "createProgress"createProgress(label, options) from readerly/progress is the same line without createOut. It always prints, so you decide when to call it. Its options:
| Option | Default | Meaning |
|---|---|---|
stderr | process.stderr | Where the line goes. isTTY picks the bar or the plain line. |
now | Date.now | The clock, in milliseconds. |
shortLabel | label | The label for a terminal too narrow for label. |
intro | none | A line printed once before the first progress line, off a terminal only. |
unit | files | What 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.