Skim

Struct Skim 

Source
pub struct Skim {}

Implementations§

Source§

impl Skim

Source

pub fn run_with( options: &SkimOptions<'_>, source: Option<SkimItemReceiver>, ) -> Option<SkimOutput>

params:

  • options: the “complex” options that control how skim behaves
  • source: a stream of items to be passed to skim for filtering. If None is given, skim will invoke the command given to fetch the items.

return:

  • None: on internal errors.
  • SkimOutput: the collected key, event, query, selected items, etc.
Examples found in repository?
examples/sample.rs (line 7)
4pub fn main() {
5    let options = SkimOptions::default();
6
7    let selected_items = Skim::run_with(&options, None)
8        .map(|out| out.selected_items)
9        .unwrap_or_else(Vec::new);
10
11    for item in selected_items.iter() {
12        println!("{}", item.output());
13    }
14}
More examples
Hide additional examples
examples/nth.rs (line 15)
8pub fn main() {
9    let input = "foo 123";
10
11    let options = SkimOptionsBuilder::default().query(Some("f")).build().unwrap();
12    let item_reader = SkimItemReader::new(SkimItemReaderOption::default().nth("2").build());
13
14    let (items, opt_ingest_handle) = item_reader.of_bufread(Box::new(Cursor::new(input)));
15    let selected_items = Skim::run_with(&options, Some(items))
16        .map(|out| out.selected_items)
17        .unwrap_or_else(Vec::new);
18
19    for item in selected_items.iter() {
20        println!("{}", item.output());
21    }
22
23    if let Some(handle) = opt_ingest_handle {
24        let _ = handle.join();
25    }
26}
examples/custom_keybinding_actions.rs (line 25)
15pub fn main() {
16    // Note: `accept` is a keyword used define custom actions.
17    // For full list of accepted keywords see `parse_event` in `src/event.rs`.
18    // `delete` and `create` are arbitrary keywords used for this example.
19    let options = SkimOptionsBuilder::default()
20        .multi(true)
21        .bind(vec!["bs:abort", "Enter:accept"])
22        .build()
23        .unwrap();
24
25    if let Some(out) = Skim::run_with(&options, None) {
26        match out.final_key {
27            // Delete each selected item
28            Key::Backspace => out.selected_items.iter().for_each(|i| fake_delete_item(&i.text())),
29            // Create a new item based on the query
30            Key::Enter => fake_create_item(out.query.as_ref()),
31            _ => (),
32        }
33    }
34}
examples/downcast.rs (line 38)
22pub fn main() {
23    let options = SkimOptionsBuilder::default()
24        .height(Some("50%"))
25        .multi(true)
26        .preview(Some(""))
27        .build()
28        .unwrap();
29
30    let (tx, rx): (SkimItemSender, SkimItemReceiver) = unbounded();
31
32    tx.send(vec![Arc::new(Item { text: "a".to_string() })]).unwrap();
33    tx.send(vec![Arc::new(Item { text: "b".to_string() })]).unwrap();
34    tx.send(vec![Arc::new(Item { text: "c".to_string() })]).unwrap();
35
36    drop(tx);
37
38    let selected_items = Skim::run_with(&options, Some(rx))
39        .map(|out| out.selected_items)
40        .unwrap_or_default()
41        .iter()
42        .map(|selected_item| (**selected_item).as_any().downcast_ref::<Item>().unwrap().to_owned())
43        .collect::<Vec<Item>>();
44
45    for item in selected_items {
46        println!("{:?}", item);
47    }
48}
examples/custom_item.rs (line 42)
22pub fn main() {
23    let options = SkimOptionsBuilder::default()
24        .height(Some("50%"))
25        .multi(true)
26        .preview(Some("")) // preview should be specified to enable preview window
27        .build()
28        .unwrap();
29
30    let (tx_item, rx_item): (SkimItemSender, SkimItemReceiver) = unbounded();
31    let _ = tx_item.send(vec![Arc::new(MyItem {
32        inner: "color aaaa".to_string(),
33    })]);
34    let _ = tx_item.send(vec![Arc::new(MyItem {
35        inner: "bbbb".to_string(),
36    })]);
37    let _ = tx_item.send(vec![Arc::new(MyItem {
38        inner: "ccc".to_string(),
39    })]);
40    drop(tx_item); // so that skim could know when to stop waiting for more items.
41
42    let selected_items = Skim::run_with(&options, Some(rx_item))
43        .map(|out| out.selected_items)
44        .unwrap_or_else(Vec::new);
45
46    for item in selected_items.iter() {
47        println!("{}", item.output());
48    }
49}
examples/option_builder.rs (line 17)
5pub fn main() {
6    let options = SkimOptionsBuilder::default()
7        .height(Some("50%"))
8        .multi(true)
9        .build()
10        .unwrap();
11    let item_reader = SkimItemReader::default();
12
13    //==================================================
14    // first run
15    let input = "aaaaa\nbbbb\nccc";
16    let (items, opt_ingest_handle) = item_reader.of_bufread(Box::new(Cursor::new(input)));
17    let selected_items = Skim::run_with(&options, Some(items))
18        .map(|out| out.selected_items)
19        .unwrap_or_else(Vec::new);
20
21    for item in selected_items.iter() {
22        println!("{}", item.output());
23    }
24
25    if let Some(handle) = opt_ingest_handle {
26        let _ = handle.join();
27    }
28
29    //==================================================
30    // second run
31    let input = "11111\n22222\n333333333";
32    let (items, opt_ingest_handle) = item_reader.of_bufread(Box::new(Cursor::new(input)));
33    let selected_items = Skim::run_with(&options, Some(items))
34        .map(|out| out.selected_items)
35        .unwrap_or_else(Vec::new);
36
37    for item in selected_items.iter() {
38        println!("{}", item.output());
39    }
40
41    if let Some(handle) = opt_ingest_handle {
42        let _ = handle.join();
43    }
44}

Auto Trait Implementations§

§

impl Freeze for Skim

§

impl RefUnwindSafe for Skim

§

impl Send for Skim

§

impl Sync for Skim

§

impl Unpin for Skim

§

impl UnwindSafe for Skim

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

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> 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, 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.