FuzzyFinder

Struct FuzzyFinder 

Source
pub struct FuzzyFinder<String: Sync + Send + 'static> {
    pub kind: FuzzyKind,
    pub matcher: Nucleo<String>,
    pub input: Input,
    pub item_count: u32,
    pub matched_item_count: u32,
    pub index: u32,
    /* private fields */
}
Expand description

The fuzzy picker of file. it may be in one of 3 kinds:

  • for file, it will match against paths from current folder,
  • for lines, it will match against any text of a text files from current folder,
  • for actions, it will match against any text from help, allowing to run an action when you forgot the keybind.

Internally, it’s just :

  • a Nucleo matcher,
  • a few u32: index, top (first displayed index), height of the window, item count, matched item count
  • and the current selection as a string.

The matcher is used externally by display to get the displayed matches and internally to update the selection when the user type something or move around.

The interface shouldn’t change much, except to add more shortcut.

Fields§

§kind: FuzzyKind

kind of fuzzy: Line (match lines into text file), File (match file against their name), Action (match an action)

§matcher: Nucleo<String>

The fuzzy matcher

§input: Input

typed input by the user

§item_count: u32

number of parsed item

§matched_item_count: u32

number of matched item

§index: u32

selected index. Should always been smaller than matched_item_count

Implementations§

Source§

impl<String: Sync + Send + 'static> FuzzyFinder<String>
where Vec<String>: FromIterator<String>,

Source

pub fn new(kind: FuzzyKind) -> Self

Creates a new fuzzy matcher for this kind.

Source

pub fn set_height(self, height: usize) -> Self

Set the terminal height of the fuzzy picker. It should always be called after new

Source

pub fn should_preview(&self) -> bool

True iff a preview should be built for this fuzzy finder. It only makes sense to preview files not lines nor actions.

Source

pub fn injector(&self) -> Injector<String>

Get an Injector from the internal Nucleo instance.

Source

pub fn update_input(&mut self, append: bool)

if insert char: append = true, if delete char: append = false,

Source

pub fn tick(&mut self, force: bool)

tick the matcher. refresh the selection if the status changed or if force = true.

Source

pub fn top_bottom(&self) -> (u32, u32)

Calculate the first & last matching index which should be stored in content. It assumes the index can’t change by more than one at a time. Returning both values (top & bottom) allows to avoid mutating self here. This method can be called in crate::io::Display to know what matches should be drawn.

It should only be called after a refresh of the matcher to be sure the matched_item_count is correct.

Several cases :

  • if there’s not enough element to fill the display, take everything.
  • if the selection is in the top 4 rows, scroll up if possible.
  • if the selection is in the last 4 rows, scroll down if possible.
  • otherwise, don’t move.

Scrolling is done only at top or bottom, not in the middle of the screen. It feels more natural.

Source

pub fn resize(&mut self, height: usize)

Set the new height and refresh the content.

Source

pub fn pick(&self) -> Option<String>

Returns the selected element, if its index is valid. It should never return None if the content isn’t empty.

Source§

impl FuzzyFinder<String>

Source

pub fn navigate(&mut self, direction: Direction)

Source

pub fn find_files(&self, current_path: PathBuf)

Source

pub fn find_action(&self, help: String)

Source

pub fn find_line(&self, tokio_greper: TokioCommand)

Trait Implementations§

Source§

impl<String: Sync + Send + 'static> Default for FuzzyFinder<String>
where Vec<String>: FromIterator<String>,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<String> Freeze for FuzzyFinder<String>

§

impl<String> !RefUnwindSafe for FuzzyFinder<String>

§

impl<String> Send for FuzzyFinder<String>

§

impl<String> Sync for FuzzyFinder<String>

§

impl<String> Unpin for FuzzyFinder<String>

§

impl<String> !UnwindSafe for FuzzyFinder<String>

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T
where T: Send,