Struct xmt::XMT

source · []
pub struct XMT { /* private fields */ }
Expand description

Root formatter struct.

Implementations

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");

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");

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");

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()});

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");

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");

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

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.

Prompt the user for input.

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 name = xmt.prompt("What is your name?")?;
println!("Hello, {}!", name);
Returns

The text entered by the user.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.