Spinner and progress bar usage.
Spinner and progress bar usage.
Demonstrates:
out.spinner(),out.progress(),spinner.wrap(), and automatic suppression in non-TTY or--jsonmode.
Usage
bash
npx tsx examples/spinner-progress.ts
npx tsx examples/spinner-progress.ts --json # spinners suppressed, JSON output
echo | npx tsx examples/spinner-progress.ts # non-TTY: spinners silentSource
ts
/**
* Spinner and progress bar usage.
*
* Demonstrates: `out.spinner()`, `out.progress()`, `spinner.wrap()`, and
* automatic suppression in non-TTY or `--json` mode.
*
* Usage:
* npx tsx examples/spinner-progress.ts
* npx tsx examples/spinner-progress.ts --json # spinners suppressed, JSON output
* echo | npx tsx examples/spinner-progress.ts # non-TTY: spinners silent
*/
import { , , } from '@kjanat/dreamcli';
function (: number): <void> {
return new (() => (, ));
}
const = ('build')
.('Build the project (demonstrates spinners and progress)')
.('steps', .().(5).('Number of build steps'))
.(async ({ , }) => {
// --- Spinner: indeterminate work ---
const = .('Preparing build environment...');
await (1000);
.('Installing dependencies...');
await (800);
.('Environment ready');
// --- Spinner with wrap(): auto-succeed/fail ---
const = .('Linting...');
await .((600), {
: 'Lint passed',
: 'Lint failed',
});
// --- Progress bar: determinate work ---
const = .({ : ., : 'Compiling' });
for (let = 0; < .; ++) {
await (300);
.();
}
.('Build complete');
.(`Built ${.} modules`);
});
void ('build').().();