Struct cargo::core::shell::Shell

source ·
pub struct Shell { /* private fields */ }
Expand description

An abstraction around console output that remembers preferences for output verbosity and color.

Implementations§

source§

impl Shell

source

pub fn new() -> Shell

Creates a new shell (color choice and verbosity), defaulting to ‘auto’ color and verbose output.

source

pub fn from_write(out: Box<dyn Write>) -> Shell

Creates a shell from a plain writable object, with no color, and max verbosity.

source

pub fn set_needs_clear(&mut self, needs_clear: bool)

Sets whether the next print should clear the current line.

source

pub fn is_cleared(&self) -> bool

Returns true if the needs_clear flag is unset.

source

pub fn err_width(&self) -> TtyWidth

Returns the width of the terminal in spaces, if any.

source

pub fn is_err_tty(&self) -> bool

Returns true if stderr is a tty.

source

pub fn out(&mut self) -> &mut dyn Write

Gets a reference to the underlying stdout writer.

source

pub fn err(&mut self) -> &mut dyn Write

Gets a reference to the underlying stderr writer.

source

pub fn err_erase_line(&mut self)

Erase from cursor to end of line.

source

pub fn status<T, U>(&mut self, status: T, message: U) -> CargoResult<()>where T: Display, U: Display,

Shortcut to right-align and color green a status message.

source

pub fn status_header<T>(&mut self, status: T) -> CargoResult<()>where T: Display,

source

pub fn status_with_color<T, U>( &mut self, status: T, message: U, color: Color ) -> CargoResult<()>where T: Display, U: Display,

Shortcut to right-align a status message.

source

pub fn verbose<F>(&mut self, callback: F) -> CargoResult<()>where F: FnMut(&mut Shell) -> CargoResult<()>,

Runs the callback only if we are in verbose mode.

source

pub fn concise<F>(&mut self, callback: F) -> CargoResult<()>where F: FnMut(&mut Shell) -> CargoResult<()>,

Runs the callback if we are not in verbose mode.

source

pub fn error<T: Display>(&mut self, message: T) -> CargoResult<()>

Prints a red ‘error’ message.

source

pub fn warn<T: Display>(&mut self, message: T) -> CargoResult<()>

Prints an amber ‘warning’ message.

source

pub fn note<T: Display>(&mut self, message: T) -> CargoResult<()>

Prints a cyan ‘note’ message.

source

pub fn set_verbosity(&mut self, verbosity: Verbosity)

Updates the verbosity of the shell.

source

pub fn verbosity(&self) -> Verbosity

Gets the verbosity of the shell.

source

pub fn set_color_choice(&mut self, color: Option<&str>) -> CargoResult<()>

Updates the color choice (always, never, or auto) from a string..

source

pub fn color_choice(&self) -> ColorChoice

Gets the current color choice.

If we are not using a color stream, this will always return Never, even if the color choice has been set to something else.

source

pub fn err_supports_color(&self) -> bool

Whether the shell supports color.

source

pub fn out_supports_color(&self) -> bool

source

pub fn write_stdout( &mut self, fragment: impl Display, color: &ColorSpec ) -> CargoResult<()>

Write a styled fragment

Caller is responsible for deciding whether Shell::verbosity is affects output.

source

pub fn write_stderr( &mut self, fragment: impl Display, color: &ColorSpec ) -> CargoResult<()>

Write a styled fragment

Caller is responsible for deciding whether Shell::verbosity is affects output.

source

pub fn print_ansi_stderr(&mut self, message: &[u8]) -> CargoResult<()>

Prints a message to stderr and translates ANSI escape code into console colors.

source

pub fn print_ansi_stdout(&mut self, message: &[u8]) -> CargoResult<()>

Prints a message to stdout and translates ANSI escape code into console colors.

source

pub fn print_json<T: Serialize>(&mut self, obj: &T) -> CargoResult<()>

Trait Implementations§

source§

impl Debug for Shell

source§

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

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

impl Default for Shell

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Shell

§

impl !Send for Shell

§

impl !Sync for Shell

§

impl Unpin for Shell

§

impl !UnwindSafe for Shell

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

§

type Output = T

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V