pub struct Shell {
output: ShellOut,
verbosity: Verbosity,
needs_clear: bool,
}
Expand description
An abstraction around console output that remembers preferences for output verbosity and color.
Fields§
§output: ShellOut
Wrapper around stdout/stderr. This helps with supporting sending output to a memory buffer which is useful for tests.
verbosity: Verbosity
How verbose messages should be.
needs_clear: bool
Flag that indicates the current line needs to be cleared before printing. Used when a progress bar is currently displayed.
Implementations§
source§impl Shell
impl Shell
sourcepub fn new() -> Shell
pub fn new() -> Shell
Creates a new shell (color choice and verbosity), defaulting to ‘auto’ color and verbose output.
sourcepub fn from_write(out: Box<dyn Write>) -> Shell
pub fn from_write(out: Box<dyn Write>) -> Shell
Creates a shell from a plain writable object, with no color, and max verbosity.
sourcefn print(
&mut self,
status: &dyn Display,
message: Option<&dyn Display>,
color: &Style,
justified: bool
) -> CargoResult<()>
fn print( &mut self, status: &dyn Display, message: Option<&dyn Display>, color: &Style, justified: bool ) -> CargoResult<()>
Prints a message, where the status will have color
color, and can be justified. The
messages follows without color.
sourcepub fn set_needs_clear(&mut self, needs_clear: bool)
pub fn set_needs_clear(&mut self, needs_clear: bool)
Sets whether the next print should clear the current line.
sourcepub fn is_cleared(&self) -> bool
pub fn is_cleared(&self) -> bool
Returns true
if the needs_clear
flag is unset.
sourcepub fn is_err_tty(&self) -> bool
pub fn is_err_tty(&self) -> bool
Returns true
if stderr is a tty.
sourcepub fn err_erase_line(&mut self)
pub fn err_erase_line(&mut self)
Erase from cursor to end of line.
sourcepub fn status<T, U>(&mut self, status: T, message: U) -> CargoResult<()>where
T: Display,
U: Display,
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.
pub fn status_header<T>(&mut self, status: T) -> CargoResult<()>where T: Display,
sourcepub fn status_with_color<T, U>(
&mut self,
status: T,
message: U,
color: &Style
) -> CargoResult<()>where
T: Display,
U: Display,
pub fn status_with_color<T, U>( &mut self, status: T, message: U, color: &Style ) -> CargoResult<()>where T: Display, U: Display,
Shortcut to right-align a status message.
sourcepub fn verbose<F>(&mut self, callback: F) -> CargoResult<()>where
F: FnMut(&mut Shell) -> CargoResult<()>,
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.
sourcepub fn concise<F>(&mut self, callback: F) -> CargoResult<()>where
F: FnMut(&mut Shell) -> CargoResult<()>,
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.
sourcepub fn error<T: Display>(&mut self, message: T) -> CargoResult<()>
pub fn error<T: Display>(&mut self, message: T) -> CargoResult<()>
Prints a red ‘error’ message.
sourcepub fn warn<T: Display>(&mut self, message: T) -> CargoResult<()>
pub fn warn<T: Display>(&mut self, message: T) -> CargoResult<()>
Prints an amber ‘warning’ message.
sourcepub fn note<T: Display>(&mut self, message: T) -> CargoResult<()>
pub fn note<T: Display>(&mut self, message: T) -> CargoResult<()>
Prints a cyan ‘note’ message.
sourcepub fn set_verbosity(&mut self, verbosity: Verbosity)
pub fn set_verbosity(&mut self, verbosity: Verbosity)
Updates the verbosity of the shell.
sourcepub fn set_color_choice(&mut self, color: Option<&str>) -> CargoResult<()>
pub fn set_color_choice(&mut self, color: Option<&str>) -> CargoResult<()>
Updates the color choice (always, never, or auto) from a string..
sourcepub fn color_choice(&self) -> ColorChoice
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.
sourcepub fn err_supports_color(&self) -> bool
pub fn err_supports_color(&self) -> bool
Whether the shell supports color.
pub fn out_supports_color(&self) -> bool
sourcepub fn write_stdout(
&mut self,
fragment: impl Display,
color: &Style
) -> CargoResult<()>
pub fn write_stdout( &mut self, fragment: impl Display, color: &Style ) -> CargoResult<()>
Write a styled fragment
Caller is responsible for deciding whether Shell::verbosity
is affects output.
sourcepub fn write_stderr(
&mut self,
fragment: impl Display,
color: &Style
) -> CargoResult<()>
pub fn write_stderr( &mut self, fragment: impl Display, color: &Style ) -> CargoResult<()>
Write a styled fragment
Caller is responsible for deciding whether Shell::verbosity
is affects output.
sourcepub fn print_ansi_stderr(&mut self, message: &[u8]) -> CargoResult<()>
pub fn print_ansi_stderr(&mut self, message: &[u8]) -> CargoResult<()>
Prints a message to stderr and translates ANSI escape code into console colors.
sourcepub fn print_ansi_stdout(&mut self, message: &[u8]) -> CargoResult<()>
pub fn print_ansi_stdout(&mut self, message: &[u8]) -> CargoResult<()>
Prints a message to stdout and translates ANSI escape code into console colors.
pub fn print_json<T: Serialize>(&mut self, obj: &T) -> CargoResult<()>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 64 bytes