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

FZF Image preview with imgcat #6088

Open
stevenwalton opened this issue Sep 4, 2024 · 1 comment
Open

FZF Image preview with imgcat #6088

stevenwalton opened this issue Sep 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@stevenwalton
Copy link

What Operating System(s) are you seeing this problem on?

macOS

Which Wayland compositor or X11 Window manager(s) are you using?

No response

WezTerm version

wezterm 20240203-110809-5046fc22

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

No, and I'll explain why below

Describe the bug

fzf has a preview option but wezterm imgcat causes it to hang. In fzf's preview panel you'll see Loading .. up at the top right and it will never finish.

I'll show below that there is something unique about wezterm imgcat so I do not believe this is purely an fzf issue, though I'm sure they could make improvements to help too. But fzf is highly used (64k stars, 2.5k forks) so I think a lot of people are having this issue.

To Reproduce

# brew install fzf
FZF_DEFAULT_OPTS='--preview "wezterm imgcat {}"'
fzf
# type "png" or something

Result looks like this (sometimes the loading message does not show)

Screenshot 2024-09-04 at 1 35 53 PM

I've tried a few variations such as with wezterm imgcat --width $FZF_PREVIEW_COLUMNS {}, using the tmux passthrough option, and even very small image widths. To confirm, using the command from the cli works properly and is very fast.

Screenshot 2024-09-04 at 1 39 02 PM

Configuration

I don't think there is any relevant settings in my config but they are located here and I believe the configs are highly readable (if not, let me know and I can explain and will improve)

Expected Behavior

Expected behavior is to display image

Logs

No response

Anything else?

In part this is due to fzf taking some time but there seems to be some uniqueness to wezterm imgcat. This is the only one that actually hangs for me

chafa

# brew install chafa
FZF_DEFAULT_OPTS='--preview="chafa -s 40 {}"'

This works almost instantly (it is dependent upon your window size)

Screenshot 2024-09-04 at 1 54 04 PM

catimg

Also works almost instantly

# brew install catimg
FZF_DEFAULT_OPTS='--preview="catimg -w 40 {}"'

Screenshot 2024-09-04 at 1 55 37 PM

wezterm imgcat

hangs

FZF_DEFAULT_OPTS='--preview="wezterm imgcat --width 40 {}"'

Screenshot 2024-09-04 at 1 56 42 PM

I saw #5049 and #1951 where it seems there might be some confusion so I included the relevant install commands for brew and I think we have everything to reproduce the issue. If you need anything else, let me know.

I actually ran all the commands with \fzf to avoid my alias (fzf='fd --no-ignore | fzf'), so this should work out of the box

@AnonymouX47
Copy link

AnonymouX47 commented Sep 17, 2024

This has already been addressed in junegunn/fzf#3646. See the last two comments.

In short, the issue lies with fzf reading responses to queries sent by wezterm imgcat (which it requires to properly size and encode images), causing it to stall (waiting for the responses that never get to it).

Very little could be done to mitigate this on wezterm's end such as using the TIOCGWINSZ ioctl to get terminal size info and environment variables to guess the terminal's name/version (but this is very messy and I personally discourage it).

In the end the main issue still lies with fzf. It should give room for previewers to query the terminal as this is required for various for various functionality!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants