Skip to main content

Matchmaker

Struct Matchmaker 

Source
pub struct Matchmaker<T: SSS, S: Selection = T> {
    pub worker: Worker<T>,
    pub render_config: RenderConfig,
    pub tui_config: TerminalConfig,
    pub exit_config: ExitConfig,
    pub selector: Selector<T, S>,
    pub event_handlers: EventHandlers<T, S>,
    pub interrupt_handlers: InterruptHandlers<T, S>,
}
Expand description

The main entrypoint of the library. To use:

  1. create your worker (T -> Columns)
  2. Determine your identifier
  3. Instantiate this with Matchmaker::new_from_raw(..)
  4. Register your handlers 4.5 Start and connect your previewer
  5. Call mm.pick() or mm.pick_with_matcher(&mut matcher)

Fields§

§worker: Worker<T>§render_config: RenderConfig§tui_config: TerminalConfig§exit_config: ExitConfig§selector: Selector<T, S>§event_handlers: EventHandlers<T, S>§interrupt_handlers: InterruptHandlers<T, S>

Implementations§

Source§

impl Matchmaker<Indexed<Segmented<Either<String, Text<'static>>>>, Segmented<Either<String, Text<'static>>>>

Source

pub fn new_from_config( render_config: RenderConfig, tui_config: TerminalConfig, worker_config: WorkerConfig, exit_config: ExitConfig, ) -> (Self, ConfigInjector, OddEnds)

Creates a new Matchmaker from a config::BaseConfig.

Source§

impl<T: SSS, S: Selection> Matchmaker<T, S>

Source

pub fn new(worker: Worker<T>, selector: Selector<T, S>) -> Self

Examples found in repository?
examples/pick_1.rs (line 8)
4pub async fn mm_get<T: SSS + Render + Clone>(items: impl IntoIterator<Item = T>) -> Result<T> {
5    let worker = Worker::new_single_column();
6    worker.append(items);
7    let selector = Selector::new(Indexed::identifier).disabled();
8    let mm = Matchmaker::new(worker, selector);
9
10    mm.pick_default().await.first()
11}
More examples
Hide additional examples
examples/basic.rs (line 11)
5async fn main() -> Result<()> {
6    let items = vec!["item1", "item2", "item3"];
7
8    let worker = Worker::new_single_column();
9    worker.append(items);
10    let selector = Selector::new(Indexed::identifier);
11    let mm = Matchmaker::new(worker, selector);
12
13    match mm.pick_default().await {
14        Ok(v) => {
15            println!("{}", v[0]);
16        }
17        Err(err) => match err {
18            MatchError::Abort(1) => {
19                eprintln!("cancelled");
20            }
21            _ => {
22                eprintln!("Error: {err}");
23            }
24        },
25    }
26
27    Ok(())
28}
Source

pub fn config_render(&mut self, render: RenderConfig) -> &mut Self

Configure the UI

Source

pub fn config_tui(&mut self, tui: TerminalConfig) -> &mut Self

Configure the TUI

Source

pub fn config_exit(&mut self, exit: ExitConfig) -> &mut Self

Configure exit conditions

Source

pub fn register_event_handler<F>(&mut self, event: Event, handler: F)
where F: Fn(&mut MMState<'_, '_, T, S>, &Event) + 'static,

Register a handler to listen on Events

Source

pub fn register_boxed_event_handler( &mut self, event: Event, handler: DynamicMethod<T, S, Event>, )

Register a boxed handler to listen on Events

Source

pub fn register_interrupt_handler<F>( &mut self, interrupt: Interrupt, handler: F, )
where F: Fn(&mut MMState<'_, '_, T, S>) + 'static,

Register a handler to listen on Interrupts

Source

pub fn register_boxed_interrupt_handler( &mut self, variant: Interrupt, handler: BoxedHandler<T, S>, )

Register a boxed handler to listen on Interrupts

Source

pub async fn pick<A: ActionExt>( self, builder: PickOptions<'_, T, S, A>, ) -> Result<Vec<S>>

The main method of the Matchmaker. It starts listening for events and renders the TUI with ratatui. It successfully returns with all the selected items selected when the Accept action is received.

Source

pub async fn pick_default(self) -> Result<Vec<S>>

Examples found in repository?
examples/pick_1.rs (line 10)
4pub async fn mm_get<T: SSS + Render + Clone>(items: impl IntoIterator<Item = T>) -> Result<T> {
5    let worker = Worker::new_single_column();
6    worker.append(items);
7    let selector = Selector::new(Indexed::identifier).disabled();
8    let mm = Matchmaker::new(worker, selector);
9
10    mm.pick_default().await.first()
11}
More examples
Hide additional examples
examples/basic.rs (line 13)
5async fn main() -> Result<()> {
6    let items = vec!["item1", "item2", "item3"];
7
8    let worker = Worker::new_single_column();
9    worker.append(items);
10    let selector = Selector::new(Indexed::identifier);
11    let mm = Matchmaker::new(worker, selector);
12
13    match mm.pick_default().await {
14        Ok(v) => {
15            println!("{}", v[0]);
16        }
17        Err(err) => match err {
18            MatchError::Abort(1) => {
19                eprintln!("cancelled");
20            }
21            _ => {
22                eprintln!("Error: {err}");
23            }
24        },
25    }
26
27    Ok(())
28}
Source§

impl<T: SSS, S: Selection> Matchmaker<T, S>

Source

pub fn register_print_handler( &mut self, print_handle: AppendOnly<String>, output_separator: String, formatter: Arc<RenderFn<T>>, )

Causes Action::Print to print to stdout.

Source

pub fn register_execute_handler(&mut self, formatter: Arc<RenderFn<T>>)

Causes Action::Execute to cause the program to execute the program specified by its payload. Note:

  • not intended for direct use.
  • Assumes preview and cmd formatter are the same.
Source

pub fn register_become_handler(&mut self, formatter: Arc<RenderFn<T>>)

Causes Action::Become to cause the program to become the program specified by its payload. Note:

  • not intended for direct use.
  • Assumes preview and cmd formatter are the same.

Trait Implementations§

Source§

impl<T: SSS + Debug, S: Selection + Debug> Debug for Matchmaker<T, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, S> Freeze for Matchmaker<T, S>

§

impl<T, S = T> !RefUnwindSafe for Matchmaker<T, S>

§

impl<T, S = T> !Send for Matchmaker<T, S>

§

impl<T, S = T> !Sync for Matchmaker<T, S>

§

impl<T, S> Unpin for Matchmaker<T, S>

§

impl<T, S> UnsafeUnpin for Matchmaker<T, S>

§

impl<T, S = T> !UnwindSafe for Matchmaker<T, S>

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

Source§

fn take_from(&mut self, maybe: Option<T>)

Merge from maybe by taking.
Source§

fn clone_from(&mut self, maybe: &Option<T>)
where T: Clone,

Merge from maybe by cloning.
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> TransformExt for T

Source§

fn transform<Q>(self, transform: impl FnOnce(T) -> Q) -> Q

Source§

fn transform_if(self, condition: bool, transform: impl FnOnce(T) -> T) -> T

Example Read more
Source§

fn modify<Q>(self, modify: impl FnOnce(&mut T) -> Q) -> T

Source§

fn modify_if<Q>(self, condition: bool, modify: impl FnOnce(&mut T) -> Q) -> T

Example Read more
Source§

fn cmp_exch<'a, E>(&'a mut self, expected: E, new: T) -> bool
where &'a mut T: PartialEq<E>,

Example Read more
Source§

fn dbg(self) -> T
where T: Debug,

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