Out
Output channel available inside action handlers.
Provides structured methods for stdout/stderr, JSON output, spinners, progress bars, and tables. The real implementation lives in src/core/output/; this interface defines the shape that handlers consume.
Out is a framework-created, non-exhaustive value: obtain instances from action parameters, createOutput(), or createCaptureOutput() — do not implement it. New readonly members may be added in minor releases.
- Import:
@kjanat/dreamcli - Export kind: interface
- Declared in:
src/core/schema/command.ts - Source link:
src/core/schema/command.ts:163
Signatures
interface Out {}Members
Properties
outBrand
Framework-construction seal. Obtain Out values from DreamCLI; do not implement this interface.
outBrand: never;jsonMode
Whether the output channel is in JSON mode (--json flag active).
Handlers can check this to skip decorative output (spinners, progress bars, ANSI formatting) when machine-readable output is expected.
jsonMode: boolean;verbosity
Active output verbosity for this command execution.
Root --quiet/-q resolves to 'quiet'. Most handlers should emit informational output through info(), status(), spinner(), or progress() and let the channel suppress it automatically. Read this property only when custom rendering or expensive optional work genuinely depends on the active verbosity.
verbosity: Verbosity;isTTY
Whether stdout is connected to a TTY (terminal).
Handlers can check this to decide whether to emit decorative output (spinners, progress bars, ANSI color codes). When false, the output is being piped or redirected — skip interactive decorations.
Note: jsonMode takes precedence — when jsonMode is true, decorative output should be suppressed regardless of isTTY.
isTTY: boolean;terminalSize
Terminal dimensions captured when the output channel was created, if available.
terminalSize: TerminalSize | undefined;color
Context-aware ANSI color palette (powered by ansispeck).
Colors are enabled only when stdout is a TTY, JSON mode is off, and the environment supports color (NO_COLOR, FORCE_COLOR, --no-color, --color, CI are respected). When disabled, every formatter is an identity function — out.color.red('x') returns 'x' — so handlers can style unconditionally without gating on isTTY/jsonMode themselves.
color: Colors;isHyperlinkSupported
Whether OSC 8 terminal hyperlinks should be emitted.
Honors explicit --no-hyperlinks/--hyperlinks argv flags first, then NO_HYPERLINKS, then FORCE_HYPERLINKS, falling back to isTTY. Handlers rendering their own out.color.link(...) output can gate on this to keep OSC 8 escapes out of piped or opted-out contexts.
isHyperlinkSupported: boolean;Methods
log
Write to stdout (normal output).
log(message: string): void;info
Informational (may be suppressed in quiet mode).
info(message: string): void;status
Status line to stderr, suppressed in quiet mode.
Keeps stdout clean for piping; for success and progress notes like Wrote <path> that scripts silence with --quiet.
status(message: string): void;warn
Warning to stderr.
warn(message: string): void;error
Error to stderr.
error(message: string): void;setExitCode
Request a process exit code without emitting error-shaped output.
Use this for check/status commands that should print normal output but still signal a non-zero status to scripts. This does not stop execution; later calls overwrite earlier calls, and thrown errors still win.
setExitCode(code: number): void;json
Emit a structured JSON value to stdout.
Always serialises value as JSON to stdout regardless of output mode. Prefer this over log(JSON.stringify(...)) so the output channel can enforce consistent formatting and future features (pretty-print in TTY, streaming JSON, etc.).
json(value: unknown): void;table
Render tabular data.
- TTY mode (non-JSON): Pretty-print aligned columns with headers.
- JSON mode (
--json): Emit the rows as a JSON array to stdout. - Piped (non-TTY, non-JSON): Same aligned text output as TTY (useful for
grep,awk, etc.). - Pass
{ format: 'text', stream: 'stderr' }to keep a human-readable side channel whilejson()writes machine output to stdout.
When columns is omitted, columns are auto-inferred from the keys of the first row. Column headers default to the key name.
When columns is provided, both text and JSON output are projected to only the listed keys.
Render tabular data with explicit column selection.
table<T extends Record<string, unknown>>(rows: readonly T[], options: TableOptions): void;
table<T extends Record<string, unknown>>(rows: readonly T[], columns?: readonly TableColumn<T>[], options?: TableOptions): void;spinner
Create a spinner for indeterminate progress feedback.
Returns a no-op handle in quiet or JSON mode. Otherwise, non-TTY output uses a no-op handle or the configured static fallback.
spinner(text: string, options?: SpinnerOptions): SpinnerHandle;progress
Create a progress bar for measured work.
Returns a no-op handle in quiet or JSON mode. Otherwise, pass total for determinate mode (percentage bar); omit for indeterminate (pulsing).
progress(options: ProgressOptions): ProgressHandle;stopActive
Stop the currently active spinner or progress handle, if any.
TTY spinner and progress handles start setInterval timers that prevent the process from exiting until a terminal method (stop, succeed, fail, done) is called. If a handler throws before reaching that call, the timer leaks and the process hangs.
Call stopActive() in a finally block after handler execution to guarantee cleanup. It is idempotent — safe to call when no handle is active, or when the handle was already stopped.
The framework calls this automatically in runCommand() and cli().run(). Direct users of createOutput() should call it themselves after the handler returns or throws.
stopActive(): void;