pub struct View { /* private fields */ }view only.Expand description
How to present a Present result: the format, the colour mode, and the
layout policy. JSON never contains ANSI.
Pretty output decides colour and width for the stream it goes to: a
success for stdout, a failure for stderr. So a failure printed to a
terminal is coloured while a success piped to a file is not.
Self::capture under ColorMode::Auto holds no escape sequence when
that stream is not a terminal.
The colour, width, and style settings are one RenderOptions, which
Self::render_options returns. A setter takes the name of its setting
and returns the view changed, as on RenderOptions. Self::format and
Self::is_quiet read the format and the quiet setting.
Implementations§
Source§impl View
impl View
Sourcepub const fn new(format: OutputFormat, color: ColorMode) -> Self
pub const fn new(format: OutputFormat, color: ColorMode) -> Self
Build a view in format and color that prints successes. Width,
buffer, minimum, fallback, styles, and JSON layout take their defaults.
Sourcepub const fn json_layout(self, layout: JsonLayout) -> Self
pub const fn json_layout(self, layout: JsonLayout) -> Self
Lay out JSON output as layout. This beats the environment.
Sourcepub const fn json_layout_envs(self, names: &'static [&'static str]) -> Self
pub const fn json_layout_envs(self, names: &'static [&'static str]) -> Self
Replace the ordered environment names read for the JSON layout. An empty slice disables lookup.
Sourcepub fn resolved_json_layout(self) -> JsonLayout
pub fn resolved_json_layout(self) -> JsonLayout
JSON layout: the CLI’s choice, then the environment, then the default. It reads the process environment.
Sourcepub const fn styles(self, styles: RenderOptions) -> Self
pub const fn styles(self, styles: RenderOptions) -> Self
Take the theme, record style, table frame, row separation, and the
variables they read from styles. Its colour and width settings are
ignored; the view owns those.
Sourcepub const fn theme(self, theme: Theme) -> Self
pub const fn theme(self, theme: Theme) -> Self
Draw each role in the style theme gives it, in place of
Theme::default. Colour is still the colour mode’s choice:
ColorMode::Never writes no style. A later Self::styles
replaces this theme with its own.
Sourcepub const fn color(self, color: ColorMode) -> Self
pub const fn color(self, color: ColorMode) -> Self
Write colour as color says, in place of the mode given to
Self::new.
Sourcepub const fn quiet(self, quiet: bool) -> Self
pub const fn quiet(self, quiet: bool) -> Self
Suppress a successful pretty result when quiet is true. Errors and
JSON are still written.
Sourcepub const fn format(self) -> OutputFormat
pub const fn format(self) -> OutputFormat
Pretty or JSON output, as Self::new set it.
Sourcepub const fn is_quiet(self) -> bool
pub const fn is_quiet(self) -> bool
Whether a successful pretty result is suppressed, as Self::quiet
set it.
Sourcepub const fn width(self, width: u16) -> Self
pub const fn width(self, width: u16) -> Self
Lay out pretty output to exactly width terminal cells, skipping
detection, the buffer, and the minimum.
Sourcepub const fn automatic_width_buffer(self, cells: u16) -> Self
pub const fn automatic_width_buffer(self, cells: u16) -> Self
Override the number of cells subtracted from an automatically
detected width. Zero disables the subtraction. An explicit
Self::width stays exact.
Sourcepub const fn automatic_width_buffer_envs(
self,
names: &'static [&'static str],
) -> Self
pub const fn automatic_width_buffer_envs( self, names: &'static [&'static str], ) -> Self
Replace the ordered environment names that set the buffer. An empty slice disables lookup.
Sourcepub const fn minimum_automatic_width(self, cells: u16) -> Self
pub const fn minimum_automatic_width(self, cells: u16) -> Self
Set the floor, in cells, for an automatically detected width.
Sourcepub const fn fallback_width(self, width: Option<u16>) -> Self
pub const fn fallback_width(self, width: Option<u16>) -> Self
Lay out to width cells when no width is detected. None turns the
fallback off, so tables render at their natural width.
Sourcepub const fn render_options(self) -> RenderOptions
pub const fn render_options(self) -> RenderOptions
The colour, width, and style settings pretty output renders with: the buffer, its environment names, the minimum, the fallback, and the styles.
Sourcepub fn capture(self, value: &impl Present) -> Result<Captured>
pub fn capture(self, value: &impl Present) -> Result<Captured>
Render value without writing it. Tests and alternate transports use
this path.
JSON output is value serialized in the layout
Self::resolved_json_layout returns, for stdout. Pretty output is
rendered as Self::show would write it. Colour and width are decided
for the stream Captured::stream names, from the colour mode, the
process environment, and whether that stream is a terminal.
§Errors
Returns an error when value does not serialize to JSON.
Sourcepub fn show(self, value: &impl Present) -> Result<ExitCode>
pub fn show(self, value: &impl Present) -> Result<ExitCode>
Render value and write it to the stream Self::capture picks.
Returns the exit code for main to return.
§Errors
Returns an error when value does not serialize to JSON, or when
writing to stdout or stderr fails.
Sourcepub fn emit_err(self, bin: &str, message: &str) -> Result<ExitCode>
pub fn emit_err(self, bin: &str, message: &str) -> Result<ExitCode>
Write a failure that has no Present model, such as a parse error.
Pretty output is {bin}: {message} on stderr. JSON output is an
Envelope with an ErrorBody on stdout, in this view’s layout.
The exit code is ExitCode::FAILURE in both.
§Errors
Returns an error when writing to stdout or stderr fails.