Struct skim::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)
4
5
6
7
8
9
10
11
12
13
14
pub fn main() {
    let options = SkimOptions::default();

    let selected_items = Skim::run_with(&options, None)
        .map(|out| out.selected_items)
        .unwrap_or_else(Vec::new);

    for item in selected_items.iter() {
        println!("{}", item.output());
    }
}
More examples
Hide additional examples
examples/nth.rs (line 15)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
pub fn main() {
    let input = "foo 123";

    let options = SkimOptionsBuilder::default().query(Some("f")).build().unwrap();
    let item_reader = SkimItemReader::new(SkimItemReaderOption::default().nth("2").build());

    let items = item_reader.of_bufread(Cursor::new(input));
    let selected_items = Skim::run_with(&options, Some(items))
        .map(|out| out.selected_items)
        .unwrap_or_else(Vec::new);

    for item in selected_items.iter() {
        println!("{}", item.output());
    }
}
examples/custom_keybinding_actions.rs (line 25)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pub 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", "Enter:accept"])
        .build()
        .unwrap();

    Skim::run_with(&options, None).map(|out| match out.final_key {
        // Delete each selected item
        Key::Backspace => out.selected_items.iter().for_each(|i| fake_delete_item(&i.text())),
        // Create a new item based on the query
        Key::Enter => fake_create_item(out.query.as_ref()),
        _ => (),
    });
}
examples/downcast.rs (line 38)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
pub fn main() {
    let options = SkimOptionsBuilder::default()
        .height(Some("50%"))
        .multi(true)
        .preview(Some(""))
        .build()
        .unwrap();

    let (tx, rx): (SkimItemSender, SkimItemReceiver) = unbounded();

    tx.send(Arc::new(Item { text: "a".to_string() })).unwrap();
    tx.send(Arc::new(Item { text: "b".to_string() })).unwrap();
    tx.send(Arc::new(Item { text: "c".to_string() })).unwrap();

    drop(tx);

    let selected_items = Skim::run_with(&options, Some(rx))
        .map(|out| out.selected_items)
        .unwrap_or_else(Vec::new)
        .iter()
        .map(|selected_item| (**selected_item).as_any().downcast_ref::<Item>().unwrap().to_owned())
        .collect::<Vec<Item>>();

    for item in selected_items {
        println!("{:?}", item);
    }
}
examples/custom_item.rs (line 42)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
pub fn main() {
    let options = SkimOptionsBuilder::default()
        .height(Some("50%"))
        .multi(true)
        .preview(Some("")) // preview should be specified to enable preview window
        .build()
        .unwrap();

    let (tx_item, rx_item): (SkimItemSender, SkimItemReceiver) = unbounded();
    let _ = tx_item.send(Arc::new(MyItem {
        inner: "color aaaa".to_string(),
    }));
    let _ = tx_item.send(Arc::new(MyItem {
        inner: "bbbb".to_string(),
    }));
    let _ = tx_item.send(Arc::new(MyItem {
        inner: "ccc".to_string(),
    }));
    drop(tx_item); // so that skim could know when to stop waiting for more items.

    let selected_items = Skim::run_with(&options, Some(rx_item))
        .map(|out| out.selected_items)
        .unwrap_or_else(Vec::new);

    for item in selected_items.iter() {
        println!("{}", item.output());
    }
}
examples/option_builder.rs (line 17)
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
pub fn main() {
    let options = SkimOptionsBuilder::default()
        .height(Some("50%"))
        .multi(true)
        .build()
        .unwrap();
    let item_reader = SkimItemReader::default();

    //==================================================
    // first run
    let input = "aaaaa\nbbbb\nccc";
    let items = item_reader.of_bufread(Cursor::new(input));
    let selected_items = Skim::run_with(&options, Some(items))
        .map(|out| out.selected_items)
        .unwrap_or_else(Vec::new);

    for item in selected_items.iter() {
        println!("{}", item.output());
    }

    //==================================================
    // second run
    let input = "11111\n22222\n333333333";
    let items = item_reader.of_bufread(Cursor::new(input));
    let selected_items = Skim::run_with(&options, Some(items))
        .map(|out| out.selected_items)
        .unwrap_or_else(Vec::new);

    for item in selected_items.iter() {
        println!("{}", item.output());
    }
}

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsAny for Twhere 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 Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.