Struct scarb_ui::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 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 anyhow(&self, error: &Error)

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

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.

Trait Implementations§

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 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.