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

UI Preview #25

Open
natecraddock opened this issue Feb 27, 2023 · 8 comments
Open

UI Preview #25

natecraddock opened this issue Feb 27, 2023 · 8 comments
Labels
enhancement New feature or request
Milestone

Comments

@natecraddock
Copy link
Owner

natecraddock commented Feb 27, 2023

Today I finally came across a use case for a UI preview. I am still not 100% sure if this is needed, but here are my thoughts

A new --preview long option that accepts a string representing a command to be run. The command accepts {} as a substitution for the current selected line. Alternate might be --command (more general)

If --preview is not null/empty, then the UI will look like this

>                                                                                             5/5
main                                               │               command output
missing-return-type                                │
nathan-pilot                                       │
php-8.1-upgrade                                    │
php-8.1-upgrade-whitespace                         │

It might also be nice to have a keybind to show/hide the preview (hidden by default?)

Again, I'm not 100% convinced this is needed. Maybe for scripts that require a preview command like this I'll just use fzf or something else.

@natecraddock natecraddock added the enhancement New feature or request label Feb 27, 2023
@kovetskiy
Copy link

Hey, thank you for the project. I am looking to replace fzf with zf.

The preview feature is actually one of the most important features for me, I use it to preview the contents of files when I use fzf in my editor.

Another example: preview contents of tmux sessions before switching to it, a pseudo-code command would be like this tmux list-windows | zf --preview "tmux-preview {}" --preview-window-size=60 | xargs -n1 -I{} tmux switch-to {}.

@natecraddock
Copy link
Owner Author

@kovetskiy thanks for expressing interest!

I've only thought about this feature for a day now, but I'm 95% certain I'll add it. I think I'll target the 0.9.0 release (0.8.0 should be released in about 2 weeks probably) so not too far away. Maybe sooner depending on how much time the remaining 0.8.0 features take.

At the same time, I want to keep zf really simple (I think fzf has way too many options). But I also want to make it useful. I think --preview and --preview-size commands are reasonable. Are you aware of any other options that might be needed?

Also, is the --preview-size a column width or a percentage?

@kovetskiy
Copy link

kovetskiy commented Mar 1, 2023

Also, is the --preview-size a column width or a percentage?

I think fzf's way is optimal in this sense, it uses a column width (or a number of rows for horizontal preview) if no % is specified, and uses percentage otherwise. But I'd personally be happy with the percentage as I often resize my windows and can't really stick to some static numbers.

Thanks!

@natecraddock
Copy link
Owner Author

Thanks for the clarification. I think I will start with a percentage, then if it seems like a fixed width is also needed I'll add that.

I thought about this more and I'm not sure how to best add this to zf's main loop. Currently I keep things very CPU efficient by using blocking reads in the UI. The problem with that is if I wanted to make subprocess calls async (which they should be for a good experience) I would need to make the read calls non-blocking. Otherwise the UI preview would not update unless a key was pressed.

This could be trivially handled by adding a sleep of sorts to the main loop. Or using evented IO. Currently Zig's async implementation is incomplete in the self-hosted compiler, but ideally I would use that for syntax support.

I do want to add this, so I'll keep thinking of solutions.

@natecraddock natecraddock added this to the 0.9.0 milestone Mar 8, 2023
@natecraddock
Copy link
Owner Author

If I'm understanding it correctly, I think std.io.poll introduced in 0.11.0 will be a good solution. ziglang/zig#14744

So I will add previews once Zig 0.11.0 is released.

@mizlan
Copy link

mizlan commented Apr 27, 2023

I am curious, will the existence of previewing functionality cause a hit to performance even if the previewing is disabled?

@natecraddock
Copy link
Owner Author

@mizlan there shouldn't be any performance impact of a disabled preview with the way I'm planning on adding preview.

I also have some fuzzy plans to add multithreading to zf so if anything, it will be even more performant in the future!

This was referenced Jun 8, 2023
@natecraddock
Copy link
Owner Author

I just merged some commits that introduces an event loop to zf, so I'll start working on this feature in the next week or so!

@natecraddock natecraddock modified the milestones: 0.9.0, 1.10.0 Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants