Progress
Determinate progress bar for operations with known completion percentage.
Preview
In progress
progress
████████████░░░░░░░░ Downloading... 60%
Completed
progress
◆ Download complete.
Usage
import { progress } from 'termprompt';
const p = progress();
p.start('Downloading...');
p.update(25);
p.update(50, 'Downloading... halfway');
p.update(100);
p.stop('Download complete.');
API
progress(config?)
Returns a Progress object.
| Config | Type | Default | Description |
|---|---|---|---|
output | Writable | process.stdout | Output stream |
Progress Methods
| Method | Description |
|---|---|
start(message: string) | Show the progress bar at 0% |
update(percent: number, message?) | Update percentage (0-100) and optionally message |
stop(message?: string, code?) | Stop and show final message |
Stop Codes
| Code | Icon |
|---|---|
0 (default) | Green diamond (success) |
| Non-zero | Red triangle (error) |
Error Handling
const p = progress();
p.start('Uploading...');
try {
await upload((pct) => p.update(pct));
p.stop('Upload complete.');
} catch (err) {
p.stop('Upload failed.', 1);
}
error stop code
▲ Upload failed.
Bar Rendering
The bar is 20 characters wide using filled (█) and empty (░) blocks. The fill amount is proportional to the percentage. The bar color uses your accent color.