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>,
pub preview: Option<Preview>,
}Expand description
The main entrypoint of the library. To use:
- create your worker (T -> Columns)
- Determine your identifier
- Instantiate this with Matchmaker::new_from_raw(..)
- Register your handlers 4.5 Start and connect your previewer
- 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>§preview: Option<Preview>Implementations§
Source§impl Matchmaker<Indexed<Segmented<String>>, Segmented<String>>
impl Matchmaker<Indexed<Segmented<String>>, Segmented<String>>
Sourcepub fn new_from_config(
render_config: RenderConfig,
tui_config: TerminalConfig,
worker_config: WorkerConfig,
) -> (Self, ConfigInjector, OddEnds)
pub fn new_from_config( render_config: RenderConfig, tui_config: TerminalConfig, worker_config: WorkerConfig, ) -> (Self, ConfigInjector, OddEnds)
Creates a new Matchmaker from a config::BaseConfig.
Source§impl<T: SSS, S: Selection> Matchmaker<T, S>
impl<T: SSS, S: Selection> Matchmaker<T, S>
Sourcepub fn new(worker: Worker<T>, selector: Selector<T, S>) -> Self
pub fn new(worker: Worker<T>, selector: Selector<T, S>) -> Self
Examples found in repository?
More 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}Sourcepub fn connect_preview(&mut self, preview: Preview)
pub fn connect_preview(&mut self, preview: Preview)
The contents of the preview are displayed in a pane when picking.
Sourcepub fn config_render(&mut self, render: RenderConfig) -> &mut Self
pub fn config_render(&mut self, render: RenderConfig) -> &mut Self
Configure the UI
Sourcepub fn config_tui(&mut self, tui: TerminalConfig) -> &mut Self
pub fn config_tui(&mut self, tui: TerminalConfig) -> &mut Self
Configure the TUI
Sourcepub fn config_exit(&mut self, exit: ExitConfig) -> &mut Self
pub fn config_exit(&mut self, exit: ExitConfig) -> &mut Self
Configure exit conditions
Sourcepub fn register_event_handler<F, I>(&mut self, events: I, handler: F)
pub fn register_event_handler<F, I>(&mut self, events: I, handler: F)
Register a handler to listen on Events
Sourcepub fn register_boxed_event_handler<I>(
&mut self,
events: I,
handler: DynamicMethod<T, S, Event>,
)where
I: IntoIterator<Item = Event>,
pub fn register_boxed_event_handler<I>(
&mut self,
events: I,
handler: DynamicMethod<T, S, Event>,
)where
I: IntoIterator<Item = Event>,
Register a boxed handler to listen on Events
Sourcepub fn register_interrupt_handler<F>(
&mut self,
interrupt: Interrupt,
handler: F,
)
pub fn register_interrupt_handler<F>( &mut self, interrupt: Interrupt, handler: F, )
Register a handler to listen on Interrupts
Sourcepub fn register_boxed_interrupt_handler(
&mut self,
variant: Interrupt,
handler: DynamicMethod<T, S, Interrupt>,
)
pub fn register_boxed_interrupt_handler( &mut self, variant: Interrupt, handler: DynamicMethod<T, S, Interrupt>, )
Register a boxed handler to listen on Interrupts
Sourcepub async fn pick<A: ActionExt>(
self,
builder: PickOptions<'_, T, S, A>,
) -> Result<Vec<S>, MatchError>
pub async fn pick<A: ActionExt>( self, builder: PickOptions<'_, T, S, A>, ) -> Result<Vec<S>, MatchError>
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.
Sourcepub async fn pick_default(self) -> Result<Vec<S>, MatchError>
pub async fn pick_default(self) -> Result<Vec<S>, MatchError>
Examples found in repository?
More 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>
impl<T: SSS, S: Selection> Matchmaker<T, S>
pub fn register_print_handler( &mut self, print_handle: AppendOnly<String>, formatter: Arc<RenderFn<T>>, )
pub fn register_execute_handler(&mut self, formatter: Arc<RenderFn<T>>)
pub fn register_become_handler(&mut self, formatter: Arc<RenderFn<T>>)
Trait Implementations§
Auto Trait Implementations§
impl<T, S> Freeze for Matchmaker<T, S>
impl<T, S = T> !RefUnwindSafe for Matchmaker<T, S>
impl<T, S> Send for Matchmaker<T, S>where
S: Send,
impl<T, S> Sync for Matchmaker<T, S>where
S: Send,
impl<T, S> Unpin for Matchmaker<T, S>
impl<T, S = T> !UnwindSafe for Matchmaker<T, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> MaybeExt for T
impl<T> MaybeExt for T
Source§fn maybe_take(&mut self, maybe: Option<T>)
fn maybe_take(&mut self, maybe: Option<T>)
Merge from maybe by taking.
Source§fn maybe_clone(&mut self, maybe: &Option<T>)where
T: Clone,
fn maybe_clone(&mut self, maybe: &Option<T>)where
T: Clone,
Merge from maybe by cloning.