Skip to main content

Sort

Struct Sort 

Source
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 str

Message 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: usize

Page size of the options displayed to the user.

§vim_mode: bool

Whether vim mode is enabled.

§starting_cursor: usize

Starting 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,

Source

pub const DEFAULT_FORMATTER: MultiOptionFormatter<'a, T>

Default formatter: Prints the sorted list joined by commas.

Source

pub const DEFAULT_PAGE_SIZE: usize = crate::config::DEFAULT_PAGE_SIZE

Default page size of the list of options.

Source

pub const DEFAULT_VIM_MODE: bool = crate::config::DEFAULT_VIM_MODE

Default setting for Vim mode (disabled by default).

Source

pub const DEFAULT_STARTING_CURSOR: usize = 0

Default index where the cursor starts.

Source

pub const DEFAULT_HELP_MESSAGE: Option<&'a str>

Help message instructing how to reorder the items.

Source

pub fn new(message: &'a str, options: Vec<T>) -> Self

Creates a Sort prompt with the provided message and options.

Source

pub fn with_help_message(self, message: &'a str) -> Self

Sets the help message to be presented to the user.

Source

pub fn without_help_message(self) -> Self

Removes the help message.

Source

pub fn with_page_size(self, page_size: usize) -> Self

Sets the page size of the options displayed to the user.

Source

pub fn with_vim_mode(self, vim_mode: bool) -> Self

Enables or disables Vim-style keybindings.

Source

pub fn with_starting_cursor(self, starting_cursor: usize) -> Self

Sets the starting cursor index.

Source

pub fn with_formatter(self, formatter: MultiOptionFormatter<'a, T>) -> Self

Sets the formatter to customize how the final selected answer is printed.

Source

pub fn with_render_config(self, render_config: RenderConfig<'a>) -> Self

Sets the custom render configuration.

Source

pub fn prompt(self) -> InquireResult<Vec<T>>

Prompts the user and returns the final sorted list of elements.

Source

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.

Source

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.

Source

pub fn raw_prompt(self) -> InquireResult<Vec<ListOption<T>>>

Prompts the user and returns the final sorted list of options, preserving original index details.

Trait Implementations§

Source§

impl<'a, T: Clone> Clone for Sort<'a, T>

Source§

fn clone(&self) -> Sort<'a, T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<'a, T> !RefUnwindSafe for Sort<'a, T>

§

impl<'a, T> !Send for Sort<'a, T>

§

impl<'a, T> !Sync for Sort<'a, T>

§

impl<'a, T> !UnwindSafe for Sort<'a, T>

§

impl<'a, T> Freeze for Sort<'a, T>

§

impl<'a, T> Unpin for Sort<'a, T>
where T: Unpin,

§

impl<'a, T> UnsafeUnpin for Sort<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.