Skip to main content

Output

Struct Output 

Source
pub struct Output { /* private fields */ }
Expand description

The output channels for one command run.

Cloning is cheap: clones share the same writers.

Implementations§

Source§

impl Output

Source

pub fn stdio() -> Self

Output bound to the process stdout and stderr, with progress indicators enabled (they still hide themselves when stderr is not a TTY).

Source

pub fn capture() -> (Self, Captured)

Output bound to in-memory buffers, with progress indicators disabled.

Returns the output and a handle that reads what was written.

Source

pub fn capture_merged() -> (Self, Captured)

Output whose two channels write to one in-memory buffer, in the order of the writes, with progress indicators disabled.

The TUI uses it: its output pane shows data and diagnostics as one stream, as a terminal does. Captured::out returns the whole stream and Captured::err returns the same text. Captured::data returns only what went to the data channel.

Source

pub fn teed(&self, limit: usize) -> (Self, Captured)

Output that still writes to this output’s writers and also keeps a copy of the text, as Output::capture_merged does.

The TUI uses it for a command that runs outside it: the user sees the text live on the terminal, and the TUI shows the copy in its scrollback after it returns. Progress indicators stay as they are here (they draw on the real terminal and are not copied). The copy keeps at most about limit bytes, the end of the text; whole lines are dropped from its start. Captured::trimmed says when that happened.

The result is a TUI output (Output::is_tui): its hints are read in the TUI scrollback.

Source

pub fn progress_enabled(&self) -> bool

True when animated progress indicators may draw on the terminal.

Source

pub fn is_tui(&self) -> bool

True when this output belongs to the TUI. Error text then gives TUI next steps, not CLI flags.

Source

pub fn progress_hook(&self) -> Option<ProgressHook>

The progress record of this run, when the output has one. The TUI’s output has one; the plain CLI output does not.

Source

pub fn series_hook(&self) -> Option<SeriesHook>

The series of a repeating run, when the output has one: the TUI’s pane output has one; the plain CLI output does not.

Source

pub fn record_run(&self, metrics: &[Metric], record: RunRecord) -> bool

Hands one run to the screen’s series. Returns false when there is no series (the CLI), so the caller prints the run instead.

Source

pub fn update_progress(&self, change: impl FnOnce(&mut RunProgress))

Changes the progress record. Does nothing when there is no hook.

Source

pub fn write_out(&self, args: Arguments<'_>) -> Result<()>

Writes formatted data to the data channel. Use outln! / out!.

§Errors

Returns the writer’s error, for example BrokenPipe when a reader closes the pipe early or a storage error when stdout is a full disk.

Source

pub fn write_err(&self, args: Arguments<'_>) -> Result<()>

Writes formatted text to the diagnostic channel. Use errln! / err!.

§Errors

Returns the writer’s error.

Source

pub fn note(&self, args: Arguments<'_>)

Writes a status line to the diagnostic channel. Use note!. A failed write is dropped: see the module policy.

Source

pub fn note_saved(&self, what: &str, path: impl Display)

The one “saved to” line: <what> saved to: <where>, as a note.

Trait Implementations§

Source§

impl Clone for Output

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

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more