Skip to content
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

Pass function to preview when used as library. #394

Open
SachinMaharana opened this issue Feb 18, 2021 · 4 comments
Open

Pass function to preview when used as library. #394

SachinMaharana opened this issue Feb 18, 2021 · 4 comments

Comments

@SachinMaharana
Copy link

SachinMaharana commented Feb 18, 2021

Is there a way to pass a function to preview when used as library?

Currently i am using it as

  let options = SkimOptionsBuilder::default()
        .height(Some("30%"))
        .color(Some("molokai"))
        .reverse(true)
        .preview(Some(
            "echo {} |  sed 's/  */ /g' | cut -d' ' -f2 | xargs ps -p",
        ))
        .header(Some("Filter Processes:"))
        .build()
        .unwrap();

I would like to pass a function(fn some(arg)) to preview. i did saw the docs but couldn't find any way to do it.

@alexxbb
Copy link
Contributor

alexxbb commented Apr 19, 2021

I have a draft of this feature in works: #407

@ghost
Copy link

ghost commented Jun 4, 2021

Set preview to Some(...) value (it just can't be None). Now in your SkimItem implement preview and return one of the "Text" ItemPreview values.

Just make sure to never return ItemPreview::Global because this would invoke whatever you put in the preview config.

@kimono-koans
Copy link

@denkuy This actually works pretty well and now my only issue is that it feels laggy. I assume it's because we're back executing on one thread again. It might just be me of course, but, have you resolved this?

@kimono-koans
Copy link

I've toyed around with enough to think this is a bug. @SachinMaharana @denkuy and @alexxbb, am I crazy? Have you found a better solution?

I suppose maybe I'm trying to do something a little more intensive with fn preview() than most, but I feel like there should be a way to say "Hey, this little function is thread safe, please execute it in a different thread and don't block the interactive session" like when a thread feeds the main session fn run_with().

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants