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
impl Ui
Sourcepub fn new(verbosity: Verbosity, output_format: OutputFormat) -> Self
pub fn new(verbosity: Verbosity, output_format: OutputFormat) -> Self
Create a new Ui instance configured with the given verbosity and output format.
Sourcepub fn output_format(&self) -> OutputFormat
pub fn output_format(&self) -> OutputFormat
Get the output format of this Ui instance.
Sourcepub fn print<T: Message>(&self, message: T)
pub fn print<T: Message>(&self, message: T)
Print the message to standard output if not in quiet verbosity mode.
Sourcepub fn force_print<T: Message>(&self, message: T)
pub fn force_print<T: Message>(&self, message: T)
Print the message to standard output regardless of the verbosity mode.
Sourcepub fn verbose<T: Message>(&self, message: T)
pub fn verbose<T: Message>(&self, message: T)
Print the message to the standard output only in verbose mode.
Sourcepub fn widget<T: Widget>(&self, widget: T) -> Option<T::Handle>
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.
Sourcepub fn warn_with_code(&self, code: impl AsRef<str>, message: impl AsRef<str>)
pub fn warn_with_code(&self, code: impl AsRef<str>, message: impl AsRef<str>)
Print a warning to the user.
Sourcepub fn error_with_code(&self, code: impl AsRef<str>, message: impl AsRef<str>)
pub fn error_with_code(&self, code: impl AsRef<str>, message: impl AsRef<str>)
Print an error to the user.
Sourcepub fn anyhow(&self, error: &Error)
pub fn anyhow(&self, error: &Error)
Nicely format an anyhow::Error for display to the user, and print it with Ui::error.
Sourcepub fn warn_anyhow(&self, error: &Error)
pub fn warn_anyhow(&self, error: &Error)
Nicely format an anyhow::Error for display to the user, and print it with Ui::warn.
Sourcepub fn force_colors_enabled(&self, enable: bool)
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.
Sourcepub fn has_colors_enabled(&self) -> bool
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.
Sourcepub fn force_colors_enabled_stderr(&self, enable: bool)
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.
Sourcepub fn has_colors_enabled_stderr(&self) -> bool
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.