Expand description
Ambient output sink for the report layer.
By default the outln! / out! macros write report CONTENT to stdout, so
the CLI behaves exactly as it always has. When the user passes
--output-file <PATH>, main opens the file and calls set_file_sink
once before dispatch; from then on every outln! / out! lands in the file
instead of stdout. The sink is process-global and ambient, so no command
Options struct needs to thread the path through, and the programmatic /
NAPI consumers (which call the build_* helpers and never the print_*
dispatch) are unaffected because they never set the sink.
Progress, errors, and the “Report written to <path>” confirmation stay on
stderr (plain eprintln!); interactive terminal chrome (the --explain
tip, the combined orientation header) is gated on is_redirected so it
never pollutes the file.
Functions§
- flush
- Flush the file sink and surface the first write error, if any. No-op (Ok) when writing to stdout. Call after rendering, before the confirmation.
- is_
redirected - Whether report content is currently being redirected to a file. Used to gate interactive terminal chrome that must not land in the file.
- set_
file_ sink - Redirect all subsequent report content to
file(truncating it). Call once, before any rendering. Also resets any prior sticky write error. - write_
fmt_ line - Write a line of report content (a trailing newline is added). Routed to the
file sink when redirected, else stdout. Backs the
outln!macro. - write_
fmt_ str - Write report content without a trailing newline. Backs the
out!macro. - wrote
- Whether any report content was written to the file sink. False when stdout was the target, or when a command errored before rendering anything.