pub struct OutputManager {
pub verbose: bool,
/* private fields */
}
Expand description
The OutputManager is a nice wrapper over shell i/o functions.
It provides output nesting, various log levels and verbosity levels, as well as stack-like features for controlling more easily the indentation level of the output
Examples
Simple usage and stacked usage.
use rood::cli::OutputManager;
let verbose_mode = false;
let output = OutputManager::new(verbose_mode);
output.step("[Step 1]");
output.push().debug("Some indented verbose-only message");
output.success("[Step 1] - OK")
Using a Yes/No prompt and handling errors.
use rood::cli::OutputManager;
let output = OutputManager::new(false);
match output.prompt_yn("Really to quit?", false) {
Ok(val) => output.success(&format!("User picked: {}", val)),
Err(e) => output.error(&format!("Error: {}", e))
}
Fields
verbose: bool
Implementations
sourceimpl OutputManager
impl OutputManager
sourcepub fn new(verbose: bool) -> OutputManager
pub fn new(verbose: bool) -> OutputManager
Returns an OutputManager
of the specified verbosity.
sourcepub fn push(&self) -> OutputManager
pub fn push(&self) -> OutputManager
Returns a new OutputManager
with the same verbosity level, but with an indentation
level incremented by one.
sourcepub fn with_padding(&self, padding: i32) -> OutputManager
pub fn with_padding(&self, padding: i32) -> OutputManager
Returns a new OutputManager
with the same verbosity level, but with an indentation
level set to the level specified.
sourcepub fn step<S: AsRef<str>>(&self, msg: S)
pub fn step<S: AsRef<str>>(&self, msg: S)
Displays a step. msg
will be printed in yellow, prefixed by a +
.
sourcepub fn progress<S: AsRef<str>>(&self, msg: S)
pub fn progress<S: AsRef<str>>(&self, msg: S)
Displays a progress message. ̀msg` will be printed in white without a prefix.
sourcepub fn success<S: AsRef<str>>(&self, msg: S)
pub fn success<S: AsRef<str>>(&self, msg: S)
Displays a success message. msg
will be printed in green, prefixed by a ‘+’.
sourcepub fn debug<S: AsRef<str>>(&self, msg: S)
pub fn debug<S: AsRef<str>>(&self, msg: S)
Displays a debug message. msg
will be printed in blue, prefixed by a ‘-’.
Note: Debug messages are only printed when the verbose flag is set.
sourcepub fn error<S: AsRef<str>>(&self, msg: S)
pub fn error<S: AsRef<str>>(&self, msg: S)
Displays an error message. msg
will be printed in red, prefixed by a ‘!’.
sourcepub fn prompt<S: AsRef<str>>(&self, msg: S) -> Result<String>
pub fn prompt<S: AsRef<str>>(&self, msg: S) -> Result<String>
Displays a prompt. msg
will be printed in blue, prefixed by a ‘?’.
Will wait for user input before returning what the user typed.
sourcepub fn prompt_yn<S: AsRef<str>>(&self, msg: S, default: bool) -> Result<bool>
pub fn prompt_yn<S: AsRef<str>>(&self, msg: S, default: bool) -> Result<bool>
Displays a yes/no prompt. msg
will be printed in blue, prefixed by a ‘?’.
Will wait for user input before returning what the user selected.
sourcepub fn prompt_password<S: AsRef<str>>(&self, msg: S) -> Result<String>
pub fn prompt_password<S: AsRef<str>>(&self, msg: S) -> Result<String>
Displays a prompt for a password or any sensitive information. msg
will be printed in blue, prefixed by a ‘?’.
Will wait for user input before returning what the user typed.
pub fn clear(&self) -> Result<()>
Trait Implementations
sourceimpl Clone for OutputManager
impl Clone for OutputManager
sourcefn clone(&self) -> OutputManager
fn clone(&self) -> OutputManager
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl RefUnwindSafe for OutputManager
impl Send for OutputManager
impl Sync for OutputManager
impl Unpin for OutputManager
impl UnwindSafe for OutputManager
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more