Crate rustic_print

Source
Expand description

§Rustic Print v2

Rustic Print is a simple library for styling terminal output. It helps you render styled text blocks, interactive prompts, and tables.

§Message Display

Most functions accept either a single string or a vector of strings, making it easy to print one-liners or multi-line messages.

Single String Example:

use rustic_print::RusticPrint;

let printer = RusticPrint::new();
printer.success("Operation completed successfully!");

Multiple Lines Example:

use rustic_print::RusticPrint;

let printer = RusticPrint::new();
printer.info(vec![
    "Step 1: Initialization complete.",
    "Step 2: Processing data.",
    "Step 3: Operation finished.",
]);

§Tables

Easily render tables by providing a vector of header strings and a vector of rows (each row is a vector of string slices).

Example:

use rustic_print::RusticPrint;

let printer = RusticPrint::new();
let headers = vec!["Name", "Age", "Occupation"];
let rows = vec![
    vec!["Alice", "30", "Engineer"],
    vec!["Bob", "25", "Designer"],
    vec!["Charlie", "35", "Manager"],
];
printer.table(headers, rows);

§Confirmations

Use the confirm function to prompt the user with a yes/no question. The default answer is provided as a boolean.

Example:

use rustic_print::RusticPrint;

let printer = RusticPrint::new();
let proceed = printer.confirm("Do you want to continue?", true);

if proceed {
    println!("Continuing...");
} else {
    println!("Operation cancelled.");
}

§Interactive Choices

The choice function displays a list of options and lets the user pick one interactively.

Example:

use rustic_print::RusticPrint;

let printer = RusticPrint::new();
let options = ["Option 1", "Option 2", "Option 3"];
let selected = printer.choice("Select an option", &options, Some("Option 2"));

println!("You selected: {}", selected);

§Input with Validation

The ask function not only prompts for input but can also enforce validation via a provided closure. If the input fails validation, the prompt is repeated until a valid response is entered.

Example:

use rustic_print::RusticPrint;

let printer = RusticPrint::new();

// The validator requires the input to be at least 3 characters long.
let username = printer.ask(
    "Enter your username",
    Some("default_user"),
    Some(Box::new(|input| {
        if input.trim().len() >= 3 {
            Ok(())
        } else {
            Err("Username must be at least 3 characters long.".to_string())
        }
    }))
);

println!("Your username is: {}", username);

§Available Functions

The following functions are available on the RusticPrint struct. Click any item for more details:

For more details on each function, please refer to the full API Reference.

Modules§

block_options
style_options
table

Structs§

RusticPrint