Progress
Spinners and determinate progress indicators for terminal tasks
@crustjs/progress writes progress indicators to stderr by default. It supports task-scoped spinners, imperative handles, determinate progress, themes, injected output, and static non-TTY output.
Install
npm install @crustjs/progressQuick example
await spinner({
message: "Building",
task: async ({ updateMessage }) => {
updateMessage("Running checks");
},
});spinner() starts the indicator, awaits task, and prints a final line. The task receives updateMessage().
✓ Running checksAPI
Call spinner({ task }) for a task-scoped indicator. Call spinner() without task for a SpinnerHandle, or progress() for a ProgressHandle.
spinner(options)
await spinner({ message: "Building", task: async () => build() });
// success: ✓ Building
// failure: ✗ Buildingtask may return a value or a promise; spinner({ task }) always returns a promise. A failed task prints the error line, then rejects with the task error. Non-TTY output omits animation and cursor-control sequences.
Interactive spinners and progress indicators keep the animated frame on one row: the whole frame (spinner symbol, message, count, and any text a custom theme adds) is cut with … at its first line break or where it would reach the terminal's last column. The message is cut first, so progress() keeps its count while the symbol and count fit; the final ✓/✗ line prints the message in full. Each redraw erases only the spinner's row, so complete lines the task writes to the same terminal, such as the action's stdout() lines while the spinner draws on stderr, stay on screen after the frame they interrupted. A write without a trailing newline begins on the spinner's row and is erased by the next frame; if it wraps, only its last row is erased. Narrowing a terminal that also reflows the cursor's row can leave the start of the previous frame above the spinner.
Prop
Type
Imperative spinner
const handle = spinner({ message: "Deploying" });
handle.start();
handle.updateMessage("Uploading");
handle.stop("success", "Deployed"); // ✓ Deployedstop() defaults to "success" and later calls do nothing.
Prop
Type
progress(options)
const bar = progress({ total: 2, message: "Files" });
bar.start();
bar.advance(1);
bar.advance(1);
bar.stop("success", "Files complete");progress() renders <message> (<current>/<total>). advance() defaults to one unit, changes the count, and may replace the message.
✓ Files complete (2/2)Prop
Type
Calling advance() before start() changes the count without repainting. The updated count appears after the handle starts or in its final line.
Prop
Type
SIGINT policy
const handle = spinner({ message: "Working", sigint: false });SpinnerSigintPolicy is "exit" | false. The default "exit" policy restores the cursor and re-raises SIGINT when no other listener remains. Use false when the application owns cleanup, and call stop() from that cleanup. Calling process.exit() while an interactive spinner is running restores the cursor under either policy when the sink writes synchronously.
Custom spinner frames
spinner({ message: "Working", spinner: { frames: ["⊶", "⊷"], interval: 150 } });Built-in names are "dots", "line", "arc", and "bounce". A custom frame array must not be empty.
Themes
import { spinner } from "@crustjs/progress";
import { cyan } from "@crustjs/style";
spinner({ message: "Working", theme: { spinner: cyan } });A ProgressTheme has spinner, message, success, and error style slots. Per-call values merge over defaultTheme; PartialProgressTheme names the override type.
Output sinks
const transcript: string[] = [];
const sink: TerminalOutput = { isTTY: false, write: (text) => transcript.push(text) };
await withTerminalIO({ output: sink }, () =>
spinner({ message: "Deploying", task: async () => {} }),
);A per-call sink wins over ambient terminal output, which wins over standard error. Standard error is written through the same writer as Core's default stderr, so a spinner inside a Command Action stays in order with the action's stderr() lines; outside Windows it writes synchronously to file descriptor 2, and patching process.stderr.write does not capture it. withTerminalIO(io, fn) takes the same optional { input, output } streams as @crustjs/prompts and shares its ambient scope.
Non-interactive behavior
✓ Deploying
✗ Deploy failedA non-TTY sink gets one final line with no animation or cursor-control sequences. updateMessage() still determines the final message.
Default theme slots decide color from sink.isTTY, applying the NO_COLOR and FORCE_COLOR rules from @crustjs/style color control. Theme functions you pass, such as @crustjs/style imports, keep their own detection, which checks stdout.