Struct substrate_manager::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
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.
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) -> SubstrateResult<()>where
T: Display,
U: Display,
pub fn status<T, U>(&mut self, status: T, message: U) -> SubstrateResult<()>where T: Display, U: Display,
Shortcut to right-align and color green a status message.
pub fn status_header<T>(&mut self, status: T) -> SubstrateResult<()>where T: Display,
sourcepub fn status_with_color<T, U>(
&mut self,
status: T,
message: U,
color: Color
) -> SubstrateResult<()>where
T: Display,
U: Display,
pub fn status_with_color<T, U>( &mut self, status: T, message: U, color: Color ) -> SubstrateResult<()>where T: Display, U: Display,
Shortcut to right-align a status message.
sourcepub fn verbose<F>(&mut self, callback: F) -> SubstrateResult<()>where
F: FnMut(&mut Shell) -> SubstrateResult<()>,
pub fn verbose<F>(&mut self, callback: F) -> SubstrateResult<()>where F: FnMut(&mut Shell) -> SubstrateResult<()>,
Runs the callback only if we are in verbose mode.
sourcepub fn concise<F>(&mut self, callback: F) -> SubstrateResult<()>where
F: FnMut(&mut Shell) -> SubstrateResult<()>,
pub fn concise<F>(&mut self, callback: F) -> SubstrateResult<()>where F: FnMut(&mut Shell) -> SubstrateResult<()>,
Runs the callback if we are not in verbose mode.
sourcepub fn error<T: Display>(&mut self, message: T) -> SubstrateResult<()>
pub fn error<T: Display>(&mut self, message: T) -> SubstrateResult<()>
Prints a red ‘error’ message.
sourcepub fn warn<T: Display>(&mut self, message: T) -> SubstrateResult<()>
pub fn warn<T: Display>(&mut self, message: T) -> SubstrateResult<()>
Prints an amber ‘warning’ message.
sourcepub fn note<T: Display>(&mut self, message: T) -> SubstrateResult<()>
pub fn note<T: Display>(&mut self, message: T) -> SubstrateResult<()>
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>) -> SubstrateResult<()>
pub fn set_color_choice(&mut self, color: Option<&str>) -> SubstrateResult<()>
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: &ColorSpec
) -> SubstrateResult<()>
pub fn write_stdout( &mut self, fragment: impl Display, color: &ColorSpec ) -> SubstrateResult<()>
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: &ColorSpec
) -> SubstrateResult<()>
pub fn write_stderr( &mut self, fragment: impl Display, color: &ColorSpec ) -> SubstrateResult<()>
Write a styled fragment
Caller is responsible for deciding whether Shell::verbosity is affects output.
sourcepub fn print_ansi_stderr(&mut self, message: &[u8]) -> SubstrateResult<()>
pub fn print_ansi_stderr(&mut self, message: &[u8]) -> SubstrateResult<()>
Prints a message to stderr and translates ANSI escape code into console colors.
sourcepub fn print_ansi_stdout(&mut self, message: &[u8]) -> SubstrateResult<()>
pub fn print_ansi_stdout(&mut self, message: &[u8]) -> SubstrateResult<()>
Prints a message to stdout and translates ANSI escape code into console colors.
pub fn print_json<T: Serialize>(&mut self, obj: &T) -> SubstrateResult<()>
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>
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where C: Color,
§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more