Struct RusticPrint

Source
pub struct RusticPrint {}

Implementations§

Source§

impl RusticPrint

Source

pub fn new() -> RusticPrint

Creates a new instance of RusticPrint.

§Returns

A new RusticPrint instance.

Source

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.

Source

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.
Source

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.
Source

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.
Source

pub fn success<T>(&self, messages: T)
where T: Into<Messages>,

Prints a success block with black text on a green background.

The block is labeled with “OK” and includes padding.

§Arguments
  • messages - The message(s) to display, convertible into Messages.
§Panics

Panics if rendering the success block fails.

Source

pub fn caution<T>(&self, messages: T)
where T: Into<Messages>,

Prints a caution block with grey text on a dark red background.

The block is labeled “CAUTION” and uses a custom prefix along with padding.

§Arguments
  • messages - The message(s) to display, convertible into Messages.
§Panics

Panics if rendering the caution block fails.

Source

pub fn error<T>(&self, messages: T)
where T: Into<Messages>,

Prints an error block with grey text on a dark red background.

The block is labeled “ERROR” and includes padding.

§Arguments
  • messages - The error message(s) to display, convertible into Messages.
§Panics

Panics if rendering the error block fails.

Source

pub fn comment<T>(&self, messages: T)
where T: Into<Messages>,

Prints a comment block prefixed with “//”.

Useful for displaying comments or annotations.

§Arguments
  • messages - The comment message(s), convertible into Messages.
§Panics

Panics if rendering the comment block fails.

Source

pub fn warning<T>(&self, messages: T)
where T: Into<Messages>,

Prints a warning block with black text on a dark yellow background.

The block is labeled “WARNING” and includes padding.

§Arguments
  • messages - The warning message(s) to display, convertible into Messages.
§Panics

Panics if rendering the warning block fails.

Source

pub fn info<T>(&self, messages: T)
where T: Into<Messages>,

Prints an informational block with green text.

The block is labeled “INFO” and includes padding.

§Arguments
  • messages - The informational message(s) to display, convertible into Messages.
§Panics

Panics if rendering the info block fails.

Source

pub fn note<T>(&self, messages: T)
where T: Into<Messages>,

Prints a note block with dark yellow text.

The block is labeled “NOTE”, uses a custom prefix, and does not include padding.

§Arguments
  • messages - The note message(s) to display, convertible into Messages.
§Panics

Panics if rendering the note block fails

Source

pub fn listing<T>(&self, items: Vec<T>)
where T: Display,

Displays a list of items, each preceded by an asterisk.

§Arguments
  • items - A vector of items that implement the Display trait.
§Panics

Panics if printing any of the items fails.

Source

pub fn text<T>(&self, message: T)
where T: Display,

Prints text with automatic wrapping based on the terminal width.

The text is indented with a single space on each line.

§Arguments
  • message - The text to print, which implements the Display trait.
§Panics

Panics if printing the text fails.

Source

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.
Source

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.

Source

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 returns Ok(()) if valid, or an error message otherwise.
§Returns

Returns the user’s input as a String.

§Panics

Panics if reading from stdin fails.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.