[−][src]Struct termprompt::Select
Renders a select prompt.
User can select from one or more options.
Interaction returns index of an item selected in the order they appear in item
invocation or items
slice.
Examples
use dialoguer::{ Select, theme::ColorfulTheme }; use console::Term; fn main() -> std::io::Result<()> { let items = vec!["Item 1", "item 2"]; let selection = Select::with_theme(&ColorfulTheme::default()) .items(&items) .default(0) .interact_on_opt(&Term::stderr())?; match selection { Some(index) => println!("User selected item : {}", items[index]), None => println!("User did not select anything") } Ok(()) }
Implementations
impl<'a> Select<'a>
[src]
pub fn new() -> Select<'static>
[src]
Creates a select prompt builder with default theme.
pub fn with_theme(theme: &'a dyn Theme) -> Select<'a>
[src]
Creates a select prompt builder with a specific theme.
Examples
use dialoguer::{ Select, theme::ColorfulTheme }; fn main() -> std::io::Result<()> { let selection = Select::with_theme(&ColorfulTheme::default()) .item("Option A") .item("Option B") .interact()?; Ok(()) }
pub fn paged(&mut self, val: bool) -> &mut Select<'a>
[src]
Enables or disables paging
Paging is disabled by default
pub fn clear(&mut self, val: bool) -> &mut Select<'a>
[src]
Indicates whether select menu should be ereased from the screen after interaction.
The default is to clear the menu.
pub fn default(&mut self, val: usize) -> &mut Select<'a>
[src]
Sets initial selected element when select menu is rendered
Element is indicated by the index at which it appears in item
method invocation or items
slice.
pub fn item<T: ToString>(&mut self, item: T) -> &mut Select<'a>
[src]
Add a single item to the selector.
Examples
use dialoguer::Select; fn main() -> std::io::Result<()> { let selection: usize = Select::new() .item("Item 1") .item("Item 2") .interact()?; Ok(()) }
pub fn items<T: ToString>(&mut self, items: &[T]) -> &mut Select<'a>
[src]
Adds multiple items to the selector.
Examples
use dialoguer::Select; fn main() -> std::io::Result<()> { let items = vec!["Item 1", "Item 2"]; let selection: usize = Select::new() .items(&items) .interact()?; println!("{}", items[selection]); Ok(()) }
pub fn with_prompt<S: Into<String>>(&mut self, prompt: S) -> &mut Select<'a>
[src]
Sets the select prompt.
When a prompt is set the system also prints out a confirmation after the selection.
Examples
use dialoguer::Select; fn main() -> std::io::Result<()> { let selection = Select::new() .with_prompt("Which option do you prefer?") .item("Option A") .item("Option B") .interact()?; Ok(()) }
pub fn interact(&self) -> Result<usize>
[src]
Enables user interaction and returns the result.
Similar to interact_on except for the fact that it does not allow selection of the terminal. The dialog is rendered on stderr. Result contains index of a selected item.
pub fn interact_opt(&self) -> Result<Option<usize>>
[src]
Enables user interaction and returns the result.
This method is similar to interact_on_opt except for the fact that it does not allow selection of the terminal.
The dialog is rendered on stderr.
Result contains Some(index)
if user selected one of items or None
if user cancelled with 'Esc' or 'q'.
pub fn interact_on(&self, term: &Term) -> Result<usize>
[src]
Like interact but allows a specific terminal to be set.
Examples
use dialoguer::Select; use console::Term; fn main() -> std::io::Result<()> { let selection = Select::new() .item("Option A") .item("Option B") .interact_on(&Term::stderr())?; println!("User selected option at index {}", selection); Ok(()) }
pub fn interact_on_opt(&self, term: &Term) -> Result<Option<usize>>
[src]
Like interact_opt but allows a specific terminal to be set.
Examples
use dialoguer::Select; use console::Term; fn main() -> std::io::Result<()> { let selection = Select::new() .item("Option A") .item("Option B") .interact_on_opt(&Term::stdout())?; match selection { Some(position) => println!("User selected option at index {}", position), None => println!("User did not select anything") } Ok(()) }
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Select<'a>
impl<'a> !Send for Select<'a>
impl<'a> !Sync for Select<'a>
impl<'a> Unpin for Select<'a>
impl<'a> !UnwindSafe for Select<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,