Skip to main content

View

Struct View 

Source
pub struct View { /* private fields */ }
Available on crate feature 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

Source

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.

Source

pub const fn json_layout(self, layout: JsonLayout) -> Self

Lay out JSON output as layout. This beats the environment.

Source

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.

Source

pub fn resolved_json_layout(self) -> JsonLayout

JSON layout: the CLI’s choice, then the environment, then the default. It reads the process environment.

Source

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.

Source

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.

Source

pub const fn color(self, color: ColorMode) -> Self

Write colour as color says, in place of the mode given to Self::new.

Source

pub const fn quiet(self, quiet: bool) -> Self

Suppress a successful pretty result when quiet is true. Errors and JSON are still written.

Source

pub const fn format(self) -> OutputFormat

Pretty or JSON output, as Self::new set it.

Source

pub const fn is_quiet(self) -> bool

Whether a successful pretty result is suppressed, as Self::quiet set it.

Source

pub const fn width(self, width: u16) -> Self

Lay out pretty output to exactly width terminal cells, skipping detection, the buffer, and the minimum.

Source

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.

Source

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.

Source

pub const fn minimum_automatic_width(self, cells: u16) -> Self

Set the floor, in cells, for an automatically detected width.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for View

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for View

Source§

impl Debug for View

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for View

Source§

impl PartialEq for View

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for View

Auto Trait Implementations§

§

impl Forget for View

§

impl Freeze for View

§

impl RefUnwindSafe for View

§

impl Send for View

§

impl Sync for View

§

impl Unpin for View

§

impl UnsafeUnpin for View

§

impl UnwindSafe for View

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, O> Matches<O> for T
where T: PartialEq<O>,

Source§

fn validate_matches(&self, other: &O) -> bool

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.