pub struct RusticPrint {}Implementations§
Source§impl RusticPrint
impl RusticPrint
Sourcepub fn new() -> RusticPrint
pub fn new() -> RusticPrint
Sourcepub fn block<T>(&self, messages: T, block_options: BlockOptions)where
T: Into<Messages>,
pub fn block<T>(&self, messages: T, block_options: BlockOptions)where
T: Into<Messages>,
Prints a block of text using the provided messages and block options.
This function converts the input into Messages and delegates rendering to the internal
render_block function. It uses default block options if none are specified.
§Arguments
messages- The message(s) to be printed; can be a single string or multiple strings.block_options- Customization options for the block, including styling and prefix.
§Panics
Panics if rendering the block fails.
Sourcepub fn underline_with_char(
&self,
message: &str,
underline_char: char,
style_options: Option<StyleOptions>,
)
pub fn underline_with_char( &self, message: &str, underline_char: char, style_options: Option<StyleOptions>, )
Underlines the given message with a repeated character.
This function wraps around render_underline_with_char and panics if rendering fails.
§Arguments
message- The text to underline.underline_char- The character used to form the underline.style_options- Optional styling parameters.
Sourcepub fn title(&self, message: &str)
pub fn title(&self, message: &str)
Displays a title by underlining the provided message with ‘=’ characters.
The title is styled with a dark green foreground.
§Arguments
message- The title text.
Sourcepub fn section(&self, message: &str)
pub fn section(&self, message: &str)
Displays a section header by underlining the message with ‘-’ characters.
The section header is styled with a dark green foreground.
§Arguments
message- The section header text.
Sourcepub fn table(&self, headers: Vec<&str>, rows: Vec<Vec<&str>>)
pub fn table(&self, headers: Vec<&str>, rows: Vec<Vec<&str>>)
Prints a table with the specified headers and rows.
Internally, this function creates a Table instance and calls its print_table method.
§Arguments
headers- A vector of string slices representing the table headers.rows- A vector of rows, where each row is a vector of string slices.
Sourcepub fn confirm(&self, question: &str, default: bool) -> bool
pub fn confirm(&self, question: &str, default: bool) -> bool
Prompts the user for confirmation with a yes/no question.
The function enters raw mode, displays the question with default highlighting, and processes keyboard input until the user confirms with Enter.
§Arguments
question- The question to present to the user.default- The default answer if the user provides no input.
§Returns
Returns true if the user confirms (yes), otherwise false.
Sourcepub fn ask(
&self,
question: &str,
default: Option<&str>,
validator: Option<Box<dyn Fn(&str) -> Result<(), String>>>,
) -> String
pub fn ask( &self, question: &str, default: Option<&str>, validator: Option<Box<dyn Fn(&str) -> Result<(), String>>>, ) -> String
Prompts the user with a question and returns the response.
If a default value is provided and the user enters nothing, the default is used. An optional validator function can be supplied to validate the user’s input.
§Arguments
question- The question to display.default- An optional default answer.validator- An optional closure that validates the input and returnsOk(())if valid, or an error message otherwise.
§Returns
Returns the user’s input as a String.
§Panics
Panics if reading from stdin fails.
Sourcepub fn choice(
&self,
question: &str,
choices: &[&str],
default: Option<&str>,
) -> String
pub fn choice( &self, question: &str, choices: &[&str], default: Option<&str>, ) -> String
Presents a multiple-choice question to the user and returns the selected option.
The function displays a list of choices, allows navigation via arrow keys, and handles input validation. It employs raw mode for interactive input.
§Arguments
question- The prompt question.choices- A slice of choices to select from.default- An optional default choice.
§Returns
Returns the selected choice as a String.
§Panics
Panics if reading events or flushing output fails.