The output system controls how command results are serialized and rendered to the user. It supports multiple built-in formats, custom transformers, ANSI detection, and banner rendering.
The active output format is resolved in this order:
- Explicit
--output:formatflag on the command line. ReplOptions.Output.DefaultFormatconfigured at startup."human"(the built-in default).
| Format | Description |
|---|---|
human |
Plain text, intended for terminals. |
json |
JSON serialization. |
xml |
XML serialization. |
yaml |
YAML serialization. |
markdown |
Markdown table/document rendering. |
The alias yml resolves to yaml. Additional aliases can be registered.
Implement IOutputTransformer and register it to add a new format:
app.Configure<OutputOptions>(o =>
{
o.AddTransformer("csv", new CsvTransformer());
});The transformer receives the command result object and writes formatted output to the provided stream.
Map an alias to any registered format name:
app.Configure<OutputOptions>(o =>
{
o.AddAlias("spreadsheet", "csv");
});ANSI color and styling support is resolved through a chain of checks:
- Session override — a hosted session can force ANSI on or off.
- Explicit
AnsiMode— set viaOutputOptions.AnsiMode. - Environment variables —
NO_COLOR(disables),CLICOLOR_FORCE(enables),TERM(checked fordumb). - Redirection check — if stdout is redirected to a file or pipe, ANSI is disabled.
The first check that produces a definitive answer wins.
The startup banner is controlled by:
OutputOptions.BannerEnabled— master toggle (defaulttrue).BannerFormats— set of format names that allow the banner (typicallyhumanonly).--no-logoflag — suppresses the banner for the current invocation.
The banner is only rendered when the active format is in the BannerFormats set and BannerEnabled is true.
The output width used for wrapping and table layout is resolved as:
OutputOptions.PreferredWidthif set explicitly.- Detected terminal width.
OutputOptions.FallbackWidth(default120).
In interactive mode, when ANSI is supported, JSON output is syntax-highlighted automatically. This applies only to the json format rendered to a terminal — redirected or non-ANSI output remains plain.
- Configuration Reference —
OutputOptionsproperties. - Execution Pipeline — output formatting occurs at stage 11.