Struct requestty::question::RawSelectBuilder [−][src]
pub struct RawSelectBuilder<'a> { /* fields omitted */ }Expand description
The builder for a raw_select prompt.
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 requestty::{Question, DefaultSeparator}; let raw_select = Question::raw_select("theme") .message("What do you want to do?") .choices(vec![ "Order a pizza".into(), "Make a reservation".into(), DefaultSeparator, "Ask for opening hours".into(), "Contact support".into(), "Talk to the receptionist".into(), ]) .build();
Implementations
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 requestty::Question; let raw_select = Question::raw_select("theme") .message("What do you want to do?") .build();
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 requestty::{Question, Answers}; let raw_select = Question::raw_select("theme") .when(|previous_answers: &Answers| match previous_answers.get("use-default-theme") { Some(ans) => ans.as_bool().unwrap(), None => true, }) .build();
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 requestty::{Question, Answers}; let raw_select = Question::raw_select("theme") .ask_if_answered(true) .build();
Set a default index for the select
The given index will be hovered in the beginning.
If default is unspecified, the first Choice will be hovered.
Panics
If the default given is not a Choice, it will cause a panic on build
Examples
use requestty::{Question, DefaultSeparator}; let raw_select = Question::raw_select("theme") .choices(vec![ "Order a pizza".into(), "Make a reservation".into(), DefaultSeparator, "Ask for opening hours".into(), "Contact support".into(), "Talk to the receptionist".into(), ]) .default(1) .build();
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 requestty::Question; let raw_select = Question::raw_select("theme") .page_size(10) .build();
Whether to wrap around when user gets to the last element.
If should_loop is not set, it will default to true.
Examples
use requestty::Question; let raw_select = Question::raw_select("theme") .should_loop(false) .build();
Inserts a Choice with the given text.
See raw_select for more information.
Examples
use requestty::Question; let raw_select = Question::raw_select("theme") .choice("Order a Pizza") .build();
Inserts a Separator with the given text.
See raw_select for more information.
Examples
use requestty::Question; let raw_select = Question::raw_select("theme") .separator("-- custom separator text --") .build();
Inserts a DefaultSeparator.
See raw_select for more information.
Examples
use requestty::Question; let raw_select = Question::raw_select("theme") .default_separator() .build();
Extends the given iterator of Choices.
See raw_select for more information.
Examples
use requestty::{Question, DefaultSeparator}; let raw_select = Question::raw_select("theme") .choices(vec![ "Order a pizza".into(), "Make a reservation".into(), DefaultSeparator, "Ask for opening hours".into(), "Contact support".into(), "Talk to the receptionist".into(), ]) .build();
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 requestty::Question; let raw_select = Question::raw_select("theme") .transform(|choice, previous_answers, backend| { write!(backend, "({}) {}", choice.index, choice.text) }) .build();
Trait Implementations
Consumes the builder returning a Question
Auto Trait Implementations
impl<'a> !RefUnwindSafe for RawSelectBuilder<'a>impl<'a> !Send for RawSelectBuilder<'a>impl<'a> !Sync for RawSelectBuilder<'a>impl<'a> Unpin for RawSelectBuilder<'a>impl<'a> !UnwindSafe for RawSelectBuilder<'a>