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:
- 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>Implementations§
Source§impl Matchmaker<Indexed<Segmented<Either<String, Text<'static>>>>, Segmented<Either<String, Text<'static>>>>
impl Matchmaker<Indexed<Segmented<Either<String, Text<'static>>>>, Segmented<Either<String, Text<'static>>>>
Sourcepub fn new_from_config(
render_config: RenderConfig,
tui_config: TerminalConfig,
worker_config: WorkerConfig,
exit_config: ExitConfig,
preprocess_config: PreprocessOptions,
) -> (Self, ConfigInjector, OddEnds)
pub fn new_from_config( render_config: RenderConfig, tui_config: TerminalConfig, worker_config: WorkerConfig, exit_config: ExitConfig, preprocess_config: PreprocessOptions, ) -> (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
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 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>(&mut self, event: Event, handler: F)
pub fn register_event_handler<F>(&mut self, event: Event, handler: F)
Register a handler to listen on Events
Sourcepub fn register_boxed_event_handler(
&mut self,
event: Event,
handler: DynamicMethod<T, S, Event>,
)
pub fn register_boxed_event_handler( &mut self, event: Event, handler: DynamicMethod<T, S, 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: BoxedHandler<T, S>,
)
pub fn register_boxed_interrupt_handler( &mut self, variant: Interrupt, handler: BoxedHandler<T, S>, )
Register a boxed handler to listen on Interrupts
Sourcepub async fn pick<A: ActionExt>(
self,
builder: PickOptions<'_, T, S, A>,
) -> Result<Vec<S>>
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.
Sourcepub async fn pick_default(self) -> Result<Vec<S>>
pub async fn pick_default(self) -> Result<Vec<S>>
Examples found in repository?
More examples
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>
Sourcepub fn register_print_handler(
&mut self,
print_handle: AppendOnly<String>,
output_separator: String,
formatter: Arc<RenderFn<T>>,
)
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.
Sourcepub fn register_execute_handler(&mut self, formatter: Arc<RenderFn<T>>)
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.
Sourcepub fn register_become_handler(&mut self, formatter: Arc<RenderFn<T>>)
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§
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> 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
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>
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>
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