pub struct Sort<'a, T> {
pub message: &'a str,
pub options: Vec<T>,
pub help_message: Option<&'a str>,
pub page_size: usize,
pub vim_mode: bool,
pub starting_cursor: usize,
pub formatter: MultiOptionFormatter<'a, T>,
pub render_config: RenderConfig<'a>,
}Expand description
Prompt designed for sorting/re-ordering a list of items.
The user moves the cursor via ↑/↓, presses Space to select/highlight an item, and then moves that item up/down using ↑/↓ or j/k (Vim style) to change its order. Pressing Enter submits the final sorted list.
§Example
use inquire::Sort;
let options = vec!["Apple", "Banana", "Cherry"];
let sorted = Sort::new("Order your favorite fruits:", options)
.prompt()
.unwrap();Fields§
§message: &'a strMessage to be presented to the user.
options: Vec<T>Options/Items to be sorted.
help_message: Option<&'a str>Help message to be presented to the user.
page_size: usizePage size of the options displayed to the user.
vim_mode: boolWhether vim mode is enabled.
starting_cursor: usizeStarting cursor index.
formatter: MultiOptionFormatter<'a, T>Function that formats the sorted list for final display.
render_config: RenderConfig<'a>RenderConfig to apply to the rendered interface.
Implementations§
Source§impl<'a, T> Sort<'a, T>where
T: Display,
impl<'a, T> Sort<'a, T>where
T: Display,
Sourcepub const DEFAULT_FORMATTER: MultiOptionFormatter<'a, T>
pub const DEFAULT_FORMATTER: MultiOptionFormatter<'a, T>
Default formatter: Prints the sorted list joined by commas.
Sourcepub const DEFAULT_PAGE_SIZE: usize = crate::config::DEFAULT_PAGE_SIZE
pub const DEFAULT_PAGE_SIZE: usize = crate::config::DEFAULT_PAGE_SIZE
Default page size of the list of options.
Sourcepub const DEFAULT_VIM_MODE: bool = crate::config::DEFAULT_VIM_MODE
pub const DEFAULT_VIM_MODE: bool = crate::config::DEFAULT_VIM_MODE
Default setting for Vim mode (disabled by default).
Sourcepub const DEFAULT_STARTING_CURSOR: usize = 0
pub const DEFAULT_STARTING_CURSOR: usize = 0
Default index where the cursor starts.
Sourcepub const DEFAULT_HELP_MESSAGE: Option<&'a str>
pub const DEFAULT_HELP_MESSAGE: Option<&'a str>
Help message instructing how to reorder the items.
Sourcepub fn new(message: &'a str, options: Vec<T>) -> Self
pub fn new(message: &'a str, options: Vec<T>) -> Self
Creates a Sort prompt with the provided message and options.
Sourcepub fn with_help_message(self, message: &'a str) -> Self
pub fn with_help_message(self, message: &'a str) -> Self
Sets the help message to be presented to the user.
Sourcepub fn without_help_message(self) -> Self
pub fn without_help_message(self) -> Self
Removes the help message.
Sourcepub fn with_page_size(self, page_size: usize) -> Self
pub fn with_page_size(self, page_size: usize) -> Self
Sets the page size of the options displayed to the user.
Sourcepub fn with_vim_mode(self, vim_mode: bool) -> Self
pub fn with_vim_mode(self, vim_mode: bool) -> Self
Enables or disables Vim-style keybindings.
Sourcepub fn with_starting_cursor(self, starting_cursor: usize) -> Self
pub fn with_starting_cursor(self, starting_cursor: usize) -> Self
Sets the starting cursor index.
Sourcepub fn with_formatter(self, formatter: MultiOptionFormatter<'a, T>) -> Self
pub fn with_formatter(self, formatter: MultiOptionFormatter<'a, T>) -> Self
Sets the formatter to customize how the final selected answer is printed.
Sourcepub fn with_render_config(self, render_config: RenderConfig<'a>) -> Self
pub fn with_render_config(self, render_config: RenderConfig<'a>) -> Self
Sets the custom render configuration.
Sourcepub fn prompt(self) -> InquireResult<Vec<T>>
pub fn prompt(self) -> InquireResult<Vec<T>>
Prompts the user and returns the final sorted list of elements.
Sourcepub fn prompt_skippable(self) -> InquireResult<Option<Vec<T>>>
pub fn prompt_skippable(self) -> InquireResult<Option<Vec<T>>>
Prompts the user and returns the final sorted list of elements,
returning None if the operation was canceled.
Sourcepub fn raw_prompt_skippable(self) -> InquireResult<Option<Vec<ListOption<T>>>>
pub fn raw_prompt_skippable(self) -> InquireResult<Option<Vec<ListOption<T>>>>
Prompts the user and returns the final sorted list of options with original indices,
returning None if the operation was canceled.
Sourcepub fn raw_prompt(self) -> InquireResult<Vec<ListOption<T>>>
pub fn raw_prompt(self) -> InquireResult<Vec<ListOption<T>>>
Prompts the user and returns the final sorted list of options, preserving original index details.