-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow more flexibility for use as a library (#613)
* fix: revert options and context split * readd selector to options * make RankCriteria public * fmt * fix selector override * add examples * clippy * revert mangen & compgen --------- Co-authored-by: LoricAndre <loric.andre@pm.me>
- Loading branch information
1 parent
53612a7
commit 33ca402
Showing
9 changed files
with
148 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
extern crate skim; | ||
use reader::CommandCollector; | ||
use skim::prelude::*; | ||
|
||
struct BasicSkimItem { | ||
value: String, | ||
} | ||
|
||
impl SkimItem for BasicSkimItem { | ||
fn text(&self) -> Cow<str> { | ||
return Cow::Borrowed(&self.value); | ||
} | ||
} | ||
|
||
struct BasicCmdCollector { | ||
pub items: Vec<String>, | ||
} | ||
|
||
impl CommandCollector for BasicCmdCollector { | ||
fn invoke(&mut self, _cmd: &str, _components_to_stop: Arc<AtomicUsize>) -> (SkimItemReceiver, Sender<i32>) { | ||
let (tx, rx) = unbounded(); | ||
let (tx_interrupt, _rx_interrupt) = unbounded(); | ||
while let Some(value) = self.items.pop() { | ||
let item = BasicSkimItem { value }; | ||
tx.send(Arc::from(item) as Arc<dyn SkimItem>).unwrap(); | ||
} | ||
|
||
(rx, tx_interrupt) | ||
} | ||
} | ||
|
||
pub fn main() { | ||
let cmd_collector = BasicCmdCollector { | ||
items: vec![String::from("foo"), String::from("bar"), String::from("baz")], | ||
}; | ||
let options = SkimOptionsBuilder::default() | ||
.cmd_collector(Rc::from(RefCell::from(cmd_collector))) | ||
.build() | ||
.unwrap(); | ||
|
||
let selected_items = Skim::run_with(&options, None) | ||
.map(|out| out.selected_items) | ||
.unwrap_or_default(); | ||
|
||
for item in selected_items.iter() { | ||
println!("{}", item.output()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
extern crate skim; | ||
use skim::prelude::*; | ||
|
||
struct BasicSelector { | ||
pub pat: String, | ||
} | ||
|
||
impl Selector for BasicSelector { | ||
fn should_select(&self, _index: usize, item: &dyn SkimItem) -> bool { | ||
return item.text().contains(&self.pat); | ||
} | ||
} | ||
|
||
pub fn main() { | ||
let selector = BasicSelector { | ||
pat: String::from("examples"), | ||
}; | ||
let options = SkimOptionsBuilder::default() | ||
.multi(true) | ||
.selector(Some(Rc::from(selector))) | ||
.query(Some(String::from("skim/"))) | ||
.build() | ||
.unwrap(); | ||
|
||
let selected_items = Skim::run_with(&options, None) | ||
.map(|out| out.selected_items) | ||
.unwrap_or_default(); | ||
|
||
for item in selected_items.iter() { | ||
println!("{}", item.output()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters