-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Library] nth option is broken? #300
Comments
This issue is somehow a technical inconsistency.
As for how to solve this problem, I now realized that maybe customization of items won't be common? I'll try to provide more helpful reader helpers(e.g. better SkimItemReader) |
Thanks, I see it's a work in progress and things need time to stabilize and get shaped. To be honest I quite struggle using For instance, slightly modified use skim::prelude::*;
use std::fmt;
struct MyItem {
id: u32,
inner: String,
}
impl fmt::Display for MyItem {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}\t{}", self.id, self.inner)
}
}
impl SkimItem for MyItem {
fn display(&self) -> Cow<AnsiString> {
Cow::Owned(self.to_string().into())
}
fn text(&self) -> Cow<str> {
// commented lines will produce out of bound
// Cow::Borrowed(&self.inner)
// Cow::Owned(self.inner.to_string())
Cow::Owned(self.to_string())
}
}
pub fn main() {
let options = SkimOptionsBuilder::default().query(Some("7b")).build().unwrap();
let vec = vec![
MyItem {
inner: "foo".to_string(),
id: 123,
},
MyItem {
inner: "bar".to_string(),
id: 789,
},
];
let (tx_item, rx_item): (SkimItemSender, SkimItemReceiver) = unbounded();
for item in vec {
let _ = tx_item.send(Arc::new(item));
}
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 {
if let Some(item) = (*item).as_any().downcast_ref::<MyItem>() {
println!("{}", item.id);
}
}
} Matching on Actually, I found why it panics. I think the code above doesn't benefit from working with a |
I did explore how others use Current workaround of how to match on needed range:
String can be wrapped into But that's really a workaround, feels somewhat artificial. Also I noticed that |
Thanks for point this out, it is a bug.
Yes. With |
I'm talking about library use of |
@murlakatamenka Misunderstood. No longer available. |
Thank you 👍 |
examples/nth.rs
:It generates a match
foo 123
although it shouldn't match anything (2nd field consists of numbers, we match on a letter). Am I doing anything wrong?skim
in terminal works as expectedThe text was updated successfully, but these errors were encountered: