pub struct PromptBase {
pub prompt: String,
pub console: Option<Console>,
pub password: bool,
pub choices: Option<Vec<String>>,
pub case_sensitive: bool,
pub show_default: bool,
pub show_choices: bool,
}Expand description
Base configuration for all prompt types.
Holds common fields like the prompt text, optional console, password mode, choices list, case sensitivity, and display flags.
Fields§
§prompt: StringThe prompt text to display.
console: Option<Console>An optional Console for styled output. If None, writes directly to
std::io::stdout().
password: boolWhen true, input characters are masked with *.
choices: Option<Vec<String>>Optional list of valid choices. When set, the user’s response is validated against this list.
case_sensitive: boolWhether choice matching is case-sensitive (default false).
show_default: boolWhether to show the default value in the prompt string.
show_choices: boolWhether to show the list of choices in the prompt string.
Implementations§
Source§impl PromptBase
impl PromptBase
Sourcepub fn new(prompt: impl Into<String>) -> Self
pub fn new(prompt: impl Into<String>) -> Self
Create a new PromptBase with the given prompt text.
Sourcepub fn case_sensitive(self, yes: bool) -> Self
pub fn case_sensitive(self, yes: bool) -> Self
Builder: set case sensitivity for choice validation.
Sourcepub fn show_default(self, yes: bool) -> Self
pub fn show_default(self, yes: bool) -> Self
Builder: show or hide the default value.
Sourcepub fn show_choices(self, yes: bool) -> Self
pub fn show_choices(self, yes: bool) -> Self
Builder: show or hide the choices list.
Sourcepub fn render_default(&self, default: &str) -> String
pub fn render_default(&self, default: &str) -> String
Format the default value for display.
Returns " (default: value)" wrapped in the prompt.default style, or
an empty string if show_default is false.
Sourcepub fn make_prompt(&self) -> String
pub fn make_prompt(&self) -> String
Build the full prompt string including choices and default.
Returns a string like:
"Enter choice [a/b/c] (default: x): "
Sourcepub fn check_choice(&self, value: &str) -> bool
pub fn check_choice(&self, value: &str) -> bool
Check whether value is a valid choice.
If choices is None, returns true.
Otherwise returns true only if value (optionally case-insensitive)
matches one of the allowed choices.