-
Notifications
You must be signed in to change notification settings - Fork 3
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
Previewer #5
Comments
I'm glad you find this crate to be useful! Unfortunately, shelling out to an external previewer (like On the other hand, it would be sensible to expose some sort of "previewer"-type API inside the picker. This could take the form of a callback which is called by the viewer implementation when the match corresponding to the highlighted row is highlighted. The callback would, I suppose, be supplied with a reference to object corresponding to the highlighted row, the previewer window dimensions, and a mutable reference to a byte buffer which it can fill. The main performance consideration is that the callback should not block rendering in the main loop. Especially with a use case like shelling out, this can potentially be quite slow. I suppose the screen rendering could be cached, but I would leave such details to the caller implementation. I don't have time to implement this myself for the foreseeable future (i.e. the next 3-4 months) but I think it would be a great feature! I would be happy to implement this myself later on when I have more time, since I think it is useful more generally. If you're keen to implement this yourself, I am happy to consider PRs if I believe the implementation lines up with how I see this crate going forward in the future. |
@qkzk I've started to think about the previewer implementation a bit now; can you quickly summarize the way in which you would use a previewer? Note that there are some things that I am not planning to implement: anything involving ANSI string parsing (there are lots of crates to do this for you, e.g. avt has a nice ansi parser). The general shape of the API that I am considering is something like pub trait Preview<T> {
/// Backing data for the previewed content.
type Buffer;
/// Load backing data.
fn load(&self, item: &T, buffer: &mut Self::Buffer);
/// Generate the preview.
fn preview<'a>(
item: &'a T,
buffer: &'a Self::Buffer,
screen: &mut [Vec<StyledContent<Cow<'a, str>>>]
); In the end, I think it is better if As for the reason behind the decoupled This API shape is quite crude, and e.g. currently does not permit usage patterns such as an external process call in an optimal way, since you don't want to startup a new By the way, reading your comment r.e. not clearing the terminal on exit, would it be useful if the previewer implemented |
Hello, I came up to something similar while writing a file previewer for a TUI file manager. the process looks like this :
As you mentioned the building can be very slow and shouldn't block anything else. Since I try to preview every kind of file, including images/pdfs/videos... I decided to split preview building from preview rendering & navigation since it lead to a lot of code. Depending on the non blocking method you pick (async, threads ...) the "attachment" process is different. One way is to have a separate thread with a mpsc reader in a loop for building which waits for preview builder results and attach it somewhere. Obviously it consumes a lot of ressources... I couldn't find a perfect solution and I'm still looking for one. The yazi file manager does it another way, it has a work pool and everything is Hope it helps ! |
Hi, thanks for the comments! Glad to hear you've had the same thoughts as me r.e. the preview implementation and decoupled loading / screen rendering. I spent a bit of time skimming through yazi; in the end I don't think we need full async to obtain robust performance (filesystem operations don't really benefit from async vs. usual threadpool without platform specific optimizations like The plan is to have a threadpool of preview workers, with multiple 'work' queues with different priority, and for the worker threads (when not busy) to prioritize the higher priority queues. But I think from the end user this will essentially be invisible (a Unfortunately I really do not know anything about what it would take to make image rendering work so that's something to think about some time in the future. For now I will only support text-based previewers. I hope to have a working prototype some time soon! |
Hello, image rendering in the terminal is a mess. It's not maintained anymore and a ueberzug++ is the preferred candidate. But... there's also the terminal emulator Kitty which is quite popular and render images directly. |
Hello there.
I've forked your repo to adapt it a little bit in my tui file explorer. ATM all I need is a way to prevent the terminal to be reset before leaving.
I used to include skim as a fuzzy finder, since I was using the same tui crate (tuikit) from the same author.
Those crates aren't maintained anymore and I wanted to switch to Crossterm.
Migrating skim to Crossterm is possible but will require A LOT of work.
So here I am.
The only thing I miss is a file previewer.
fzf & skim allow previewing of files in the picker which is very nice.
Previewing is done with an external previewer (bat, cat, whatever) and parsed into the tui.
It means parsing ansi strings and displaying them, which is done well in some crates like skim (I already adapted it to Crossterm).
It would be a major update of your project. Have you consider it ?
The text was updated successfully, but these errors were encountered: