pub struct Skim {}Implementations§
source§impl Skim
impl Skim
sourcepub fn run_with(
options: &SkimOptions<'_>,
source: Option<SkimItemReceiver>
) -> Option<SkimOutput>
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?
More examples
examples/nth.rs (line 20)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
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, opt_ingest_handle) = item_reader.of_bufread(Box::new(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());
}
if let Some(handle) = opt_ingest_handle {
let _ = handle.join();
#[cfg(feature = "malloc_trim")]
#[cfg(target_os = "linux")]
#[cfg(target_env = "gnu")]
malloc_trim();
}
}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 33 34
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();
if let Some(out) = Skim::run_with(&options, None) {
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 49 50
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)
.into_iter()
.map(|selected_item| Item {
text: selected_item.text().to_string(),
})
.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 22)
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
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, opt_ingest_handle) = item_reader.of_bufread(Box::new(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());
}
if let Some(handle) = opt_ingest_handle {
let _ = handle.join();
#[cfg(feature = "malloc_trim")]
#[cfg(target_os = "linux")]
#[cfg(target_env = "gnu")]
malloc_trim();
}
//==================================================
// second run
let input = "11111\n22222\n333333333";
let (items, opt_ingest_handle) = item_reader.of_bufread(Box::new(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());
}
if let Some(handle) = opt_ingest_handle {
let _ = handle.join();
#[cfg(feature = "malloc_trim")]
#[cfg(target_os = "linux")]
#[cfg(target_env = "gnu")]
malloc_trim();
}
}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> 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
Mutably borrows from an owned value. Read more