Struct Shell

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

An abstraction around a Writeable object 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 stdout_println(&mut self, message: impl Display)

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) -> Option<usize>

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 err(&mut self) -> &mut dyn Write

Gets a reference to the underlying 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 supports_color(&self) -> bool

Whether the shell supports color.

Source

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

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

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 Freeze for Shell

§

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

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

impl<T> ErasedDestructor for T
where T: 'static,