Ui

Struct Ui 

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

An abstraction around console output which stores preferences for output format (human vs JSON), colour, etc.

All human-oriented messaging (basically all writes to stdout) must go through this object.

Implementations§

Source§

impl Ui

Source

pub fn new(verbosity: Verbosity, output_format: OutputFormat) -> Self

Create a new Ui instance configured with the given verbosity and output format.

Source

pub fn verbosity(&self) -> Verbosity

Get the verbosity level of this Ui instance.

Source

pub fn output_format(&self) -> OutputFormat

Get the output format of this Ui instance.

Source

pub fn print<T: Message>(&self, message: T)

Print the message to standard output if not in quiet verbosity mode.

Source

pub fn force_print<T: Message>(&self, message: T)

Print the message to standard output regardless of the verbosity mode.

Source

pub fn verbose<T: Message>(&self, message: T)

Print the message to the standard output only in verbose mode.

Source

pub fn widget<T: Widget>(&self, widget: T) -> Option<T::Handle>

Display an interactive widget and return a handle for further interaction.

The widget will be only displayed if not in quiet mode, and if the output format is text.

Source

pub fn warn(&self, message: impl AsRef<str>)

Print a warning to the user.

Source

pub fn error(&self, message: impl AsRef<str>)

Print an error to the user.

Source

pub fn warn_with_code(&self, code: impl AsRef<str>, message: impl AsRef<str>)

Print a warning to the user.

Source

pub fn error_with_code(&self, code: impl AsRef<str>, message: impl AsRef<str>)

Print an error to the user.

Source

pub fn anyhow(&self, error: &Error)

Nicely format an anyhow::Error for display to the user, and print it with Ui::error.

Source

pub fn warn_anyhow(&self, error: &Error)

Nicely format an anyhow::Error for display to the user, and print it with Ui::warn.

Source

pub fn force_colors_enabled(&self, enable: bool)

Forces colorization on or off for stdout.

This overrides the default for the current process and changes the return value of the Ui::has_colors_enabled function.

Source

pub fn has_colors_enabled(&self) -> bool

Returns true if colors should be enabled for stdout.

This honors the clicolors spec.

  • CLICOLOR != 0: ANSI colors are supported and should be used when the program isn’t piped.
  • CLICOLOR == 0: Don’t output ANSI color escape codes.
  • CLICOLOR_FORCE != 0: ANSI colors should be enabled no matter what.
Source

pub fn force_colors_enabled_stderr(&self, enable: bool)

Forces colorization on or off for stdout.

This overrides the default for the current process and changes the return value of the Ui::has_colors_enabled function.

Source

pub fn has_colors_enabled_stderr(&self) -> bool

Returns true if colors should be enabled for stderr.

This honors the clicolors spec.

  • CLICOLOR != 0: ANSI colors are supported and should be used when the program isn’t piped.
  • CLICOLOR == 0: Don’t output ANSI color escape codes.
  • CLICOLOR_FORCE != 0: ANSI colors should be enabled no matter what.

Trait Implementations§

Source§

impl Clone for Ui

Source§

fn clone(&self) -> Ui

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Ui

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Ui

§

impl RefUnwindSafe for Ui

§

impl Send for Ui

§

impl Sync for Ui

§

impl Unpin for Ui

§

impl UnwindSafe for Ui

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, 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.