| Crates.io | rustic_print |
| lib.rs | rustic_print |
| version | 0.2.1 |
| created_at | 2024-02-23 21:28:23.737099+00 |
| updated_at | 2025-02-08 22:31:55.923483+00 |
| description | A versatile Rust library for enhancing console output. It offers a range of features to create a more engaging and informative command-line interface. |
| homepage | |
| repository | https://github.com/jordan-schnur/Rustic-Print |
| max_upload_size | |
| id | 1151008 |
| size | 61,010 |
Rustic Print is a lightweight, versatile Rust library for enhancing terminal output. It simplifies the process of rendering styled text blocks, interactive prompts, and tables—ideal for building engaging and informative command-line interfaces.
Add Rustic Print to your project's Cargo.toml:
[dependencies]
rustic_print = "0.2.0"
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.",
]);
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);
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.");
}
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);
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);
The following functions are available on the RusticPrint struct:
RusticPrint::new - Create a new RusticPrint instance.RusticPrint::block - Print a styled text block.RusticPrint::underline_with_char - Underline a message with a repeated character.RusticPrint::title - Display a title with a styled underline.RusticPrint::section - Display a section header.RusticPrint::success - Print a success block with custom styling.RusticPrint::caution - Print a caution block with custom styling.RusticPrint::error - Print an error block with custom styling.RusticPrint::comment - Print a comment block prefixed with //.RusticPrint::warning - Print a warning block.RusticPrint::info - Print an informational block.RusticPrint::note - Print a note block with a custom prefix.RusticPrint::listing - Display a list of items.RusticPrint::text - Print wrapped text.RusticPrint::table - Render a table with headers and rows.RusticPrint::confirm - Prompt for a yes/no confirmation.RusticPrint::ask - Prompt for input with optional validation.RusticPrint::choice - Present an interactive choice prompt.For more details on each function, please refer to the full API Reference.