natecraddock / zf

a commandline fuzzy finder and zig package designed for filtering filepaths
MIT License
451 stars 14 forks source link

UI blocks until all results are collected #38

Open mizlan opened 1 year ago

mizlan commented 1 year ago

Would there be a way to incrementally display results? Currently if ran with rg --files | zf in home directory, there is a few seconds blocking until the prompt displays. I don't think it would be trivial to make it work but I am curious.

natecraddock commented 1 year ago

Hi @mizlan!

This is something I have thought about from time to time. My personal use case for zf is usually within the scope of a single project, so I rarely have over 10,000 files to read into zf. This means I haven't given much thought to a incremental display.

As you have observed, the current zf implementation is blocking. All of stdin is read into a buffer which is then split on lines. Those lines are then given to the UI code. The UI only runs the filtering on keypresses. So that's why you are seeing the current behavior.

But I am planning on adding a UI preview feature sometime soon (once the next Zig version is released): https://github.com/natecraddock/zf/issues/25. It seems like the next version will be the end of the month.

That feature will require me to rework the event loop to be more async. As part of that, I think it would not be difficult to read from stdin in batches to make the UI immediately available.

Another side to this is multithreading the filtering of zf. For large batches of input lines, the other issue would be making sure the filtering is very fast.

Feel free to let me know your thoughts on that!

mizlan commented 1 year ago

My personal use case for zf is usually within the scope of a single project, so I rarely have over 10,000 files to read into zf

Same! I was just curious I guess, it isn't a real problem for me almost ever in practice.

Another side to this is multithreading the filtering of zf. For large batches of input lines, the other issue would be making sure the filtering is very fast.

I think multithreading would be very very cool and interesting to see! Though I am interested in the Zig language, I am not super experienced in writing multithreaded programs, so I'm afraid I can't contribute too much, but I will be excitedly watching for updates to zf :)

natecraddock commented 1 year ago

Same! I was just curious I guess, it isn't a real problem for me almost ever in practice.

In that case I'll keep this issue open, but wait and see if there is someone with that use case. I am open to it right now, but I don't want to implement it if I don't need to.

I think multithreading would be very very cool and interesting to see! Though I am interested in the Zig language, I am not super experienced in writing multithreaded programs, so I'm afraid I can't contribute too much, but I will be excitedly watching for updates to zf :)

I'll probably get to this in the next few weeks if everything goes according to plan :)