PickerOptions

Struct PickerOptions 

Source
pub struct PickerOptions { /* private fields */ }
Expand description

Specify configuration options for a Picker.

Initialize with new or (equivalently) the Default implementation, specify options, and then convert to a Picker using the picker method.

§Example

use nucleo_picker::{render::StrRenderer, Picker, PickerOptions};

let picker: Picker<String, _> = PickerOptions::new()
    .highlight(true)
    .query("search")
    .picker(StrRenderer);

§Sort order settings

There are three settings which influence the order in which items appear on the screen.

The reversed setting only influences the layout: by default, the query is placed at the bottom of the screen, with the match list rendered bottom-up. If this is set, the query will be placed at the top of the screen, with the match list rendered top-down.

The reverse_items and sort_results are used to determine the order of the items inside the match list. The order is defined according to the following table. Here, Index refers to the order in which the picker received the items from the Injectors. If you use exactly one injector, this is guaranteed to be the same as the insertion order.

sort_resultsreverse_itemsSort priority
truefalseScore (desc) → Length (asc) → Index (asc)
truetrueScore (desc) → Length (asc) → Index (desc)
falsefalseIndex (asc)
falsetrueIndex (desc)

Implementations§

Source§

impl PickerOptions

Source

pub const fn new() -> Self

Initialize with default configuration.

Equivalent to the Default implementation, but as a const fn.

Source

pub fn picker<T: Send + Sync + 'static, R: Render<T>>( self, render: R, ) -> Picker<T, R>

Convert into a Picker.

Source

pub const fn reversed(self, reversed: bool) -> Self

Set ‘reversed’ layout.

Option false (default) will put the prompt at the bottom and render items in ascending order. Option true will put the prompt at the top and render items in descending order.

Source

pub const fn reverse_items(self, reversed: bool) -> Self

Reverse the item insert order.

This changes the index tie-break method to prefer later indices rather than earlier indices. This option is typically used with sort_results set to false, in which case the newest items sent to the picker will be placed first, rather than last.

The default is false.

Source

pub const fn sort_results(self, sort: bool) -> Self

Whether or not to sort matching items by score.

This option is useful when you just want to filter items, but preserve the original order. By default, the oldest items will appear at the beginning and the newest items will appear at the end. This can be swapped by setting reverse_items to true.

Source

pub const fn frame_interval(self, interval: Duration) -> Self

Set how long each frame should last.

This is the reciprocal of the refresh rate. The default value is Duration::from_millis(15), which corresponds to a refresh rate of approximately 67 frames per second. It is not recommended to set this to a value less than 8ms.

Source

pub const fn threads(self, threads: Option<NonZero<usize>>) -> Self

Set the number of threads used by the internal matching engine.

If None (default), use a heuristic choice based on the amount of available parallelism along with other factors.

Source

pub fn config(self, config: Config) -> Self

👎Deprecated since 0.10.0: Use native methods prefer_prefix and match_paths. The normalize and ignore_case settings are never used; use normalization and case_matching instead.

Set the internal match engine configuration (default to nucleo::Config::DEFAULT).

Source

pub const fn normalization(self, normalization: Normalization) -> Self

How to perform Unicode normalization (defaults to Normalization::Smart).

Source

pub const fn case_matching(self, case_matching: CaseMatching) -> Self

How to treat case mismatch (defaults to CaseMatching::Smart).

Source

pub const fn match_paths(self) -> Self

Enable score bonuses appropriate for matching file paths.

Source

pub const fn prefer_prefix(self, prefer_prefix: bool) -> Self

Whether to provide a bonus to matches by their distance from the start of the item.

This is disabled by default and only recommended for autocompletion use-cases, where the expectation is that the user is typing the entire match.

Source

pub const fn highlight(self, highlight: bool) -> Self

Whether or not to highlight matches (default to true).

Source

pub const fn highlight_padding(self, size: u16) -> Self

How much space to leave when rendering match highlighting (default to 3).

Source

pub const fn scroll_padding(self, size: u16) -> Self

How much space to leave around the selection when scrolling (default to 3).

Source

pub const fn prompt_padding(self, size: u16) -> Self

How much space to leave around the cursor (default to 2).

Source

pub fn query<Q: Into<String>>(self, query: Q) -> Self

Provide an initial query string for the prompt (default to "").

Trait Implementations§

Source§

impl Default for PickerOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.