Output
Handlers receive out instead of console. The output channel adapts to context automatically.
Basic Output
ts
import { } from '@kjanat/dreamcli';
('deploy').(({ }) => {
.('Informational message');
.('Warning message');
.('Error message');
});JSON Output
ts
import { } from '@kjanat/dreamcli';
const = ();
.({ : 'ok', : 42 });When the CLI is invoked with --json, structured payloads stay on stdout while plain text (log, info, warn, error) routes to stderr.
Tables
ts
import { } from '@kjanat/dreamcli';
type = { : string; : string; : number };
const = [
{ : 'web-1', : 'running', : 72 },
{ : 'worker-1', : 'degraded', : 18 },
];
const = ();
.<>(, [
{ : 'name', : 'Name' },
{ : 'status', : 'Status' },
{ : 'uptime', : 'Uptime (h)' },
]);Use a type alias (not interface) for table rows.
TypeScript's structural typing requires Record<string, unknown> compatibility.
Spinners
ts
import { } from '@kjanat/dreamcli';
const = async () => {};
const = ();
const = .('Deploying...');
await ();
.('Done');Spinners auto-disable when stdout is not a TTY (CI, piped output). In --json mode, spinners are suppressed entirely.
Progress Bars
ts
import { } from '@kjanat/dreamcli';
const = async () => {};
const = ();
const = .({
: 'Uploading',
: 100,
});
for (let = 0; <= 100; ++) {
.();
await ();
}
.('Upload complete');Output Modes
The output channel automatically adjusts behavior:
| Context | Behavior |
|---|---|
| TTY | Pretty formatting, spinners animate, colors |
| Piped | Minimal stable output, spinners suppressed |
--json | Structured JSON to stdout, everything else to stderr |
One code path, correct output everywhere.
What's Next?
- Related examples: JSON mode, Spinner and progress
- Errors — structured error handling
- Testing — capturing output in tests