@@ -7,12 +7,13 @@ use std::io::Cursor;
77/// This example demonstrates how to bind custom action callbacks to keyboard shortcuts.
88///
99/// It shows how to:
10- /// 1. Create custom action callbacks
10+ /// 1. Create custom action callbacks (both sync and async)
1111/// 2. Bind them to specific key combinations
1212/// 3. Use them interactively in skim
1313fn main ( ) {
14- // Create a custom callback that adds a prefix to the query
15- let add_prefix_callback = ActionCallback :: new ( |app : & mut skim:: tui:: App | {
14+ // Create a synchronous callback that adds a prefix to the query.
15+ // Use `new_sync` for plain closures that do not need to await anything.
16+ let add_prefix_callback = ActionCallback :: new_sync ( |app : & mut skim:: tui:: App | {
1617 // Get current query and add prefix
1718 let current_query = app. input . value . clone ( ) ;
1819
@@ -32,14 +33,17 @@ fn main() {
3233 Ok ( events)
3334 } ) ;
3435
35- // Create a callback that selects all and exits
36+ // Create an async callback that selects all and exits.
37+ // Use `new` for async closures or blocks that may await futures.
3638 let select_all_callback = ActionCallback :: new ( |app : & mut skim:: tui:: App | {
3739 let count = app. item_pool . len ( ) ;
38-
39- Ok ( vec ! [
40- Event :: Action ( Action :: SelectAll ) ,
41- Event :: Action ( Action :: Accept ( Some ( format!( "Selected {count} items" ) ) ) ) ,
42- ] )
40+ async move {
41+ // Async work could go here (e.g. HTTP requests, file I/O, …).
42+ Ok ( vec ! [
43+ Event :: Action ( Action :: SelectAll ) ,
44+ Event :: Action ( Action :: Accept ( Some ( format!( "Selected {count} items" ) ) ) ) ,
45+ ] )
46+ }
4347 } ) ;
4448
4549 // Build basic options
0 commit comments