pub struct Sort<'a> { /* private fields */ }
Expand description
Renders a sort prompt.
Returns list of indices in original items list sorted according to user input.
§Example
use dialoguer::Sort;
fn main() {
let items = vec!["foo", "bar", "baz"];
let ordered = Sort::new()
.with_prompt("Which order do you prefer?")
.items(&items)
.interact()
.unwrap();
println!("You prefer:");
for i in ordered {
println!("{}", items[i]);
}
}
Implementations§
source§impl Sort<'_>
impl Sort<'_>
sourcepub fn clear(self, val: bool) -> Self
pub fn clear(self, val: bool) -> Self
Sets the clear behavior of the menu.
The default is to clear the menu after user interaction.
sourcepub fn max_length(self, val: usize) -> Self
pub fn max_length(self, val: usize) -> Self
Sets an optional max length for a page
Max length is disabled by None
sourcepub fn with_prompt<S: Into<String>>(self, prompt: S) -> Self
pub fn with_prompt<S: Into<String>>(self, prompt: S) -> Self
Prefaces the menu with a prompt.
By default, when a prompt is set the system also prints out a confirmation after
the selection. You can opt-out of this with report
.
sourcepub fn report(self, val: bool) -> Self
pub fn report(self, val: bool) -> Self
Indicates whether to report the selected order after interaction.
The default is to report the selected order.
sourcepub fn interact(self) -> Result<Vec<usize>>
pub fn interact(self) -> Result<Vec<usize>>
Enables user interaction and returns the result.
The user can order the items with the ‘Space’ bar and the arrows. On ‘Enter’ ordered list of the incides of items will be returned.
The dialog is rendered on stderr.
Result contains Vec<index>
if user hit ‘Enter’.
This unlike interact_opt
does not allow to quit with ‘Esc’ or ‘q’.
sourcepub fn interact_opt(self) -> Result<Option<Vec<usize>>>
pub fn interact_opt(self) -> Result<Option<Vec<usize>>>
Enables user interaction and returns the result.
The user can order the items with the ‘Space’ bar and the arrows. On ‘Enter’ ordered list of the incides of items will be returned.
The dialog is rendered on stderr.
Result contains Some(Vec<index>)
if user hit ‘Enter’ or None
if user cancelled with ‘Esc’ or ‘q’.
§Example
use dialoguer::Sort;
fn main() {
let items = vec!["foo", "bar", "baz"];
let ordered = Sort::new()
.items(&items)
.interact_opt()
.unwrap();
match ordered {
Some(positions) => {
println!("You prefer:");
for i in positions {
println!("{}", items[i]);
}
},
None => println!("You did not prefer anything.")
}
}
sourcepub fn interact_on(self, term: &Term) -> Result<Vec<usize>>
pub fn interact_on(self, term: &Term) -> Result<Vec<usize>>
Like interact
but allows a specific terminal to be set.
sourcepub fn interact_on_opt(self, term: &Term) -> Result<Option<Vec<usize>>>
pub fn interact_on_opt(self, term: &Term) -> Result<Option<Vec<usize>>>
Like interact_opt
but allows a specific terminal to be set.
source§impl<'a> Sort<'a>
impl<'a> Sort<'a>
sourcepub fn with_theme(theme: &'a dyn Theme) -> Self
pub fn with_theme(theme: &'a dyn Theme) -> Self
Creates a sort prompt with a specific theme.
§Example
use dialoguer::{theme::ColorfulTheme, Sort};
fn main() {
let ordered = Sort::with_theme(&ColorfulTheme::default())
.items(&["foo", "bar", "baz"])
.interact()
.unwrap();
}
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Sort<'a>
impl<'a> !RefUnwindSafe for Sort<'a>
impl<'a> !Send for Sort<'a>
impl<'a> !Sync for Sort<'a>
impl<'a> Unpin for Sort<'a>
impl<'a> !UnwindSafe for Sort<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)