1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Demonstrates binding custom key combinations to custom actions.
extern crate skim;
use crossterm::event::{KeyCode, KeyModifiers};
use skim::prelude::*;
// No action is actually performed on your filesystem!
// This example only produce friendly print statements!
fn fake_delete_item(item: &str) {
println!("Deleting item `{item}`...");
}
fn fake_create_item(item: &str) {
println!("Creating a new item `{item}`...");
}
fn main() {
// Note: `accept` is a keyword used define custom actions.
// For full list of accepted keywords see `parse_event` in `src/event.rs`.
// `delete` and `create` are arbitrary keywords used for this example.
let options = SkimOptionsBuilder::default()
.multi(true)
.bind(vec!["bs:abort".into(), "enter:accept".into()])
.build()
.unwrap();
if let Ok(out) = Skim::run_with(options, None) {
match (out.final_key.code, out.final_key.modifiers) {
// Delete each selected item
(KeyCode::Backspace, KeyModifiers::NONE) => {
out.selected_items.iter().for_each(|i| fake_delete_item(&i.text()));
}
// Create a new item based on the query
(KeyCode::Enter, KeyModifiers::NONE) => fake_create_item(out.query.as_ref()),
_ => (),
}
}
}