pub struct OrderSelectBuilder<'a> { /* private fields */ }Expand description
Prompt that allows the user to organize a list of options.
The choices are Strings and can be multiline.

See the various methods for more details on each available option.
§Examples
use reequestty::Question;
let order_select = Question::order_select("home_tasks")
.message("Please organize the tasks to be done at home")
.choices(vec![
"Make the bed",
"Clean the dishes",
"Mow the lawn",
])
.build();Implementations§
Source§impl<'a> OrderSelectBuilder<'a>
impl<'a> OrderSelectBuilder<'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 order_select = Question::order_select("home_tasks")
.message("Organize the tasks to be done at home")
//...
.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::{Answers, Question};
let order_select = Question::order_select("home_tasks")
//...
.when(|previous_answers: &Answers| match previous_answers.get("on_vacation") {
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::{Answers, Question};
let order_select = Question::order_select("home_tasks")
//...
.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::{Answers, Question, OnEsc};
let order_select = Question::order_select("home_tasks")
//...
.on_esc(OnEsc::Terminate)
//...
.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 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.
§Panics
It will panic if the page_size is less than 5.
§Examples
use reequestty::Question;
let order_select = Question::order_select("cheese")
.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.
§Examples
use reequestty::Question;
let order_select = Question::order_select("cheese")
.should_loop(false)
.build();Sourcepub fn filter<F>(self, filter: F) -> Self
pub fn filter<F>(self, filter: F) -> Self
Function to change the final submitted value before it is displayed to the user and
added to the Answers.
It is a FnOnce that is given the answer and the previous Answers, and should
return the new answer.
This will be called after the answer has been validated.
§Examples
use reequestty::Question;
let order_select = Question::order_select("evil_home_tasks")
//...
.filter(|mut tasks, previous_answers| {
tasks.rotate_left(1);
tasks
})
//...
.build();Sourcepub fn validate<F>(self, filter: F) -> Self
pub fn validate<F>(self, filter: F) -> Self
Function to validate the submitted value before it’s returned.
It is a FnMut that is given the answer and the previous Answers, and should
return Ok(()) if the given answer is valid. If it is invalid, it should return an
Err with the error message to display to the user.
This will be called when the user presses the Enter key.
§Examples
use reequestty::Question;
let order_select = Question::order_select("home_tasks")
//...
.validate(|tasks, previous_answers| {
if tasks[0].text() == "Make the bed" {
Ok(())
} else {
Err("You have to make the bed first".to_string())
}
})
//...
.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 order_select = Question::order_select("items")
//...
.transform(|items, previous_answers, backend| {
for item in items {
write!(backend, "({}) {}, ", item.initial_index(), item.text())?;
}
Ok(())
})
//...
.build();Trait Implementations§
Source§impl<'a> Debug for OrderSelectBuilder<'a>
impl<'a> Debug for OrderSelectBuilder<'a>
Source§impl<'a> From<OrderSelectBuilder<'a>> for Question<'a>
impl<'a> From<OrderSelectBuilder<'a>> for Question<'a>
Source§fn from(builder: OrderSelectBuilder<'a>) -> Self
fn from(builder: OrderSelectBuilder<'a>) -> Self
Consumes the builder returning a Question