pub struct ExpandBuilder<'a> { /* private fields */ }Expand description
The builder for a expand prompt.
The keys are ascii case-insensitive characters. The ‘h’ option is added by the prompt and shouldn’t be defined.
The choices are represented with the Choice enum. Choice::Choice can be multi-line,
but Choice::Separators can only be single line.

See the various methods for more details on each available option.
§Examples
use reequestty::Question;
let expand = Question::expand("overwrite")
.message("Conflict on `file.rs`")
.choices(vec![
('y', "Overwrite"),
('a', "Overwrite this one and all next"),
('d', "Show diff"),
])
.default_separator()
.choice('x', "Abort")
.build();Implementations§
Source§impl<'a> ExpandBuilder<'a>
impl<'a> ExpandBuilder<'a>
Sourcepub fn message<M>(self, message: M) -> Self
pub fn message<M>(self, message: M) -> Self
The message to display when the prompt is rendered in the terminal.
It can be either a String or a FnOnce that returns a String. If it is a
function, it is passed all the previous Answers, and will be called right before the
question is prompted to the user.
If it is not given, the message defaults to “<name>: “.
§Examples
use reequestty::Question;
let expand = Question::expand("overwrite")
.message("Conflict on `file.rs`")
.build();Sourcepub fn when<W>(self, when: W) -> Self
pub fn when<W>(self, when: W) -> Self
Whether to ask the question (true) or not (false).
It can be either a bool or a FnOnce that returns a bool. If it is a
function, it is passed all the previous Answers, and will be called right before the
question is prompted to the user.
If it is not given, it defaults to true.
§Examples
use reequestty::{Question, Answers};
let expand = Question::expand("overwrite")
.when(|previous_answers: &Answers| match previous_answers.get("ignore-conflicts") {
Some(ans) => ans.as_bool().unwrap(),
None => true,
})
.build();Sourcepub fn ask_if_answered(self, ask_if_answered: bool) -> Self
pub fn ask_if_answered(self, ask_if_answered: bool) -> Self
Prompt the question even if it is answered.
By default if an answer with the given name already exists, the question will be
skipped. This can be overridden by setting ask_if_answered is set to true.
If this is not given, it defaults to false.
If you need to dynamically decide whether the question should be asked, use when.
§Examples
use reequestty::Question;
let expand = Question::expand("overwrite")
.ask_if_answered(true)
.build();Sourcepub fn on_esc<T>(self, on_esc: T) -> Self
pub fn on_esc<T>(self, on_esc: T) -> Self
Configure what to do when the user presses the Esc key.
It can be either a OnEsc or a FnOnce that returns a OnEsc. If it is a
function, it is passed all the previous Answers, and will be called right before the
question is prompted to the user.
If it is not given, it defaults to OnEsc::Ignore.
§Examples
use reequestty::{Question, OnEsc};
let expand = Question::expand("overwrite")
.on_esc(OnEsc::Terminate)
.build();Sourcepub fn default(self, default: char) -> Self
pub fn default(self, default: char) -> Self
Set a default key for the expand
If no key is entered by the user and they press Enter, the default key is used.
If default is unspecified, it defaults to the ‘h’ key.
§Panics
If the default given is not a key to a choice it will cause a panic on build
§Examples
use reequestty::Question;
let expand = Question::expand("overwrite")
.choice('d', "Show diff")
.default('d')
.build();Sourcepub fn page_size(self, page_size: usize) -> Self
pub fn page_size(self, page_size: usize) -> Self
The maximum height that can be taken by the expanded list
If the total height exceeds the page size, the list will be scrollable.
The page_size must be a minimum of 5. If page_size is not set, it will default to 15. It
will only be used if the user expands the prompt.
§Panics
It will panic if the page_size is less than 5.
§Examples
use reequestty::Question;
let expand = Question::expand("overwrite")
.page_size(10)
.build();Sourcepub fn should_loop(self, should_loop: bool) -> Self
pub fn should_loop(self, should_loop: bool) -> Self
Whether to wrap around when user gets to the last element.
If should_loop is not set, it will default to true. It will only be used if the user
expands the prompt.
§Examples
use reequestty::Question;
let expand = Question::expand("overwrite")
.should_loop(false)
.build();Sourcepub fn default_separator(self) -> Self
pub fn default_separator(self) -> Self
Inserts a DefaultSeparator
See expand for more information.
§Examples
use reequestty::Question;
let expand = Question::expand("overwrite")
.default_separator()
.build();Sourcepub fn choices<I, T>(self, choices: I) -> Self
pub fn choices<I, T>(self, choices: I) -> Self
Extends the given iterator of Choices
See expand for more information.
§Panics
It will panic if the key of any choice is ‘h’ or a duplicate.
§Examples
use reequestty::Question;
let expand = Question::expand("overwrite")
.choices(vec![
('y', "Overwrite"),
('a', "Overwrite this one and all next"),
('d', "Show diff"),
])
.build();Sourcepub fn transform<F>(self, transform: F) -> Self
pub fn transform<F>(self, transform: F) -> Self
Change the way the answer looks when displayed to the user.
It is a FnOnce that is given the answer, previous Answers and the Backend to
display the answer on. After the transform is called, a new line is also added.
It will only be called once the user finishes answering the question.
§Examples
use reequestty::Question;
let expand = Question::expand("overwrite")
.transform(|choice, previous_answers, backend| {
write!(backend, "({}) {}", choice.key, choice.text)
})
.build();Trait Implementations§
Source§impl<'a> Debug for ExpandBuilder<'a>
impl<'a> Debug for ExpandBuilder<'a>
Source§impl<'a> From<ExpandBuilder<'a>> for Question<'a>
impl<'a> From<ExpandBuilder<'a>> for Question<'a>
Source§fn from(builder: ExpandBuilder<'a>) -> Self
fn from(builder: ExpandBuilder<'a>) -> Self
Consumes the builder returning a Question