pub struct XMT { /* private fields */ }
Expand description
Root formatter struct.
Implementations
sourceimpl XMT
impl XMT
sourcepub fn print(&self, msg: &str)
pub fn print(&self, msg: &str)
Print a message.
If stdout is a TTY, the message will be printed with the style defined by the config for Level::Normal. If stdout is not a TTY, the message is printed with no formatting.
If the output mode is JSON, the message is not printed.
Example
use xmt::XMT;
let xmt = XMT::default();
xmt.print("hello world");
sourcepub fn detail(&self, msg: &str)
pub fn detail(&self, msg: &str)
Print a message.
If stdout is a TTY, the message will be printed with the style defined by the config for Level::Detail. If stdout is not a TTY or if the output mode is JSON, the message is not printed.
Example
use xmt::XMT;
let xmt = XMT::default();
xmt.detail("hello world");
sourcepub fn success(&self, msg: &str)
pub fn success(&self, msg: &str)
Print a success message.
If stdout is a TTY, the message will be printed with the style defined by the config for Level::Success. If stdout is not a TTY, the message is printed with no formatting.
Example
use xmt::XMT;
let xmt = XMT::default();
xmt.success("we did it");
sourcepub fn out<S: Serialize + Display>(&self, obj: S)
pub fn out<S: Serialize + Display>(&self, obj: S)
Output a structure.
If output mode is JSON or if stdout is not a TTY, the structure is serialized to JSON and printed to stdout. If output mode is Tree, the structure is serialized to a tree and printed to stdout. If output mode is Text, the structure is printed to stdout using fmt::Display.
Example
use serde::Serialize;
use xmt::XMT;
#[derive(Serialize)]
struct Thing {
name: String,
}
impl std::fmt::Display for Thing {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.name)
}
}
let xmt = XMT::default();
xmt.out(Thing{name: "thing".to_string()});
sourcepub fn warn(&self, msg: &str)
pub fn warn(&self, msg: &str)
Print a warning.
If stdout is a TTY, the message will be printed with the style defined by the config for Level::Warn. If stdout is not a TTY, the message is printed with no formatting.
If the output mode is set to JSON, the warning is not printed.
Example
use xmt::XMT;
let xmt = XMT::default();
xmt.warn("something strange happened");
sourcepub fn error(&self, msg: &str)
pub fn error(&self, msg: &str)
Print an error.
If error is a TTY, the message will be printed with the style defined by the config for Level::Error. If error is not a TTY, the message is printed with no formatting.
If the output mode is set to JSON, the error is not printed.
Example
use xmt::XMT;
let xmt = XMT::default();
xmt.error("something bad happened");
sourcepub fn nest(&self) -> Self
pub fn nest(&self) -> Self
Execute the provided closure in a nested scope within the global XMT instance.
Example
use xmt::XMT;
let xmt = XMT::default();
xmt.print("Hello");
xmt.nest().print("Within scope");
// Prints:
// Hello
// Within scope
sourcepub fn prompt_yn(&self, msg: &str, default: bool) -> Result<bool>
pub fn prompt_yn(&self, msg: &str, default: bool) -> Result<bool>
Prompt the user for a yes/no answer.
Errors
Returns an io::Error error if stdout is not a TTY or if reading from stdin failed.
Example
use xmt::XMT;
let xmt = XMT::default();
if xmt.prompt_yn("Are you sure?", false)? {
// do the thing
}
Returns
true
if the user answered yes, false
if the user answered no.
sourcepub fn pick<'a, E: Display>(&self, msg: &str, items: &'a [E]) -> Result<&'a E>
pub fn pick<'a, E: Display>(&self, msg: &str, items: &'a [E]) -> Result<&'a E>
Prompt the user to select an item from a list.
Errors
Returns an io::Error error if stdout is not a TTY or if reading from stdin failed.
Example
use xmt::XMT;
let xmt = XMT::default();
let choices = vec!["foo", "bar", "baz"];
let pick = xmt.pick("Pick one", &choices)?;
println!("You picked: {}", pick);
Returns
A reference to the item selected by the user.
Trait Implementations
impl Eq for XMT
impl StructuralEq for XMT
impl StructuralPartialEq for XMT
Auto Trait Implementations
impl RefUnwindSafe for XMT
impl Send for XMT
impl Sync for XMT
impl Unpin for XMT
impl UnwindSafe for XMT
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<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.