Welcome to Vifm Q&A, where you can ask questions about using Vifm. Registration is optional, anonymous posts are moderated. E-mail and GitHub logins are enabled.
0 votes
in vifm by

what's the current fileviewer command to enable chafa on vifm? the proposed solution

fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm chafa --clear -c 256 %c

currently displays me some extra text that brokes the image render.

ps: do not consider the pixelation, I think is on chafa side with tmux over foot terminal

1 Answer

0 votes
by
edited by
 
Best answer

I see that too with chafa 1.14.4, try adding --polite on:

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm}
         \ chafa --size=%pwx%ph -c 256 --polite on %c

--clear doesn't make sense within Vifm, specifiying size does.

by

flawless as always, thank you for your time

by
edited by

regarding the pixelation problem, chafa author suggested to use the option -f sixel, but when I do so, the vifm preview a row of characters instead of the image.

This happens by default with vifm outside of tmux, where the images are not pixelated, so -f sixel is implied?

how can I fix that?

by

Sixel works differently from drawing with symbols and requires at least %pd macro but %N can be helpful as well:

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm}
         \ chafa -f sixel --size=%pwx%ph --polite on %c %pd %N
by

thank you so much, it's working

by

Does this also work for macOS?

I just pasted it into my vifmrc and it fails to load.

low res
high res

by

It depends on a terminal, iTerm2 had its own protocol for displaying images where it gets a path to the file. imgcat can be used in that case (see https://github.com/vifm/vifm/issues/299).

by
edited by

Sorry, I forgot to mention:

macOS 14.7.1
ghostty
fish shell

chafa foo.png works great.

yazi is using:

{ mime = "image/{avif,hei?,jxl,svg+xml}", run = "magick" }

Sorry, I am pretty new to vifm. I switched from Yazi, since I am using vim now for a long time.
Thank you by the way for that great tool. I had it a long time on my to do list, since it is perfectly matching my muscle memory! <3

Best possible result was with:

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm},<image/*>
   \ /opt/homebrew/bin/imgcat --width %pw --height %ph %c:p

imgcat

by

ghostty seems to not understand iTerm protocol (or it's mentioned somewhere else), but I see Kitty at https://ghostty.org/docs/about. Kitty protocol is also supported by chafa, so maybe this will work:

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm},<image/*>
   \ chafa --size=%pwx%ph -f kitty --polite on %c %pd

If it doesn't work, try adding also %N %pu (needed if chafa requires access to the terminal in this case).

Hope Vifm will serve you well :)

by
edited by

Thank you very much, pictures are now shown.

Unfortunately they are not properly cleared out. When switching the
pane or hiding :view , the image persists.

EDIT: Got it:
Regarding to:
https://github.com/hpjansson/chafa/issues/77
I could either set:

fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.xpm,*.webp,*.gif
    \ chafa -f kitty -s %pwx%ph %c:p %pd %N 2>/dev/null
    \ %pc
    \ kitty +icat --clear --silent %pd

or

set previewoptions=hardgraphicsclear

I recognized that setting %N is slowing down the preview rendering, so I just used your proposed:

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm},<image/*>
   \ chafa -f kitty --size=%pwx%ph --polite on %c %pd

I’ll guess Vifm will definitely serve me well. The most important about a tool is the community behind it. I am wondering why nvim gets that much attention (plugins etc.) but Vifm is still under the radar. Even without lua scripting it's a fantastic file viewer for all vim/nvim enthusiasts.

For sure, lua and package managers as well as customisable status bars etc. could enhance the UX. I hope the community will take over at some point.

For now I appreciate your support! :-)

:wq

by

I just wanted to let you know a pretty easy solution to get images, pdfs and as well videos rendered in quick view with a nice tool timg which uses several image protocols like sixel, kitty iterm2 and as well symbols as backup. No need for Ueberzug anymore!

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm},<image/*>
        \ timg -p kitty -g%pwx%ph %c %pd

fileviewer {*.pdf},<application/pdf> timg -p kitty --frames=1 -g%pwx%ph %c %pd

See also:
https://github.com/hzeller/timg/issues/27#issuecomment-2791272904

by
edited by

I recently switched from sixel to kitty, and while this is working on vifm outside tmux

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm,*.webp,*.svg} chafa -f kitty --size=%pwx%ph --polite on %c %pd

is not working while on tmux, could it be related to this?

on a side note, I'm am able to correctly render image with chafa on tmux

edit: tried timg too as suggested by sHii

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm,*.webp,*.svg} timg -p kitty -g%pwx%ph %c %pd

but still no image (preview remains blank, no other character printed at all)

by

I think the preview should work with %pd regardless of how printing is done and I'm not sure if chafa even supports that Unicode hack.

chafa inside tmux inside kitty doesn't work for me in a shell, but since it works for you, you can try specifying --passthrough tmux in your fileviewer command. chafa autodetects terminal multiplexer by default, but the detection might not work the same inside Vifm.

by

chafa inside tmux inside kitty doesn't work for me in a shell

I'm on current master of both chafa and tmux, and I'm using ghostty terminal emulator, maybe this can help you replicate?

you can try specifying --passthrough tmux in your fileviewer command.
chafa autodetects terminal multiplexer by default, but the detection
might not work the same inside Vifm.

I edited the fileviewer command to this

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm,*.webp,*.svg} chafa -f kitty --passthrough tmux --size=%pwx%ph --polite on %c %pd %N

without success, but I can't grasp if it's a me problem

by

I did more tests using also kitty terminal emulator along ghostty

kitty terminal emulator
-- chafa
works with 0 rendering lag

-- chafa inside vifm

chafa --size=%pwx%ph %c %pd

works with 0 rendering lag

-- chafa inside tmux
works with 0 rendering lag

-- chafa inside vifm inside tmux

chafa --size=%pwx%ph %c %pd

do not work

chafa --passthrough tmux --size=%pwx%ph %c %pd

do not work

ghostty terminal emulator
-- chafa
works with minimal rendering lag

-- chafa inside vifm

chafa --size=%pwx%ph %c %pd

works with minimal rendering lag

-- chafa inside tmux
ghostty window crash

-- chafa inside vifm inside tmux
ghostty window crash

by

do you think vifm could work with the chafa/tmux/kitty stack? I will swap ghostty with kitty entirely if this is possible, otherwise have to remain on sixel terminal, vifm image preview is crucial to me

by

Why do you want to use chafa or kitty protocol specifically?

By the way, kitty has its own plugin (or whatever it's called) which seems to handle tmux properly:

fileviewer {*.png,*.jpg}
    \ kitten icat --silent --scale-up --place=%pwx%ph@%pxx%py %c >/dev/tty </dev/tty %N
    \ %pc
    \ kitten icat --silent --clear >/dev/tty </dev/tty %N

ghostty might need %N instead of %pd or some environment variable set. That's the curse of graphics in terminals, the ways to make it work are terribly fragile with some being somewhat more robust. You could also try using ueberzugpp via plugin, this can be more reliable, faster and shouldn't depend on a terminal. Trying with ghostty for me requires building it first (there is no package).

by
edited by

I tried with ueberzugpp via its lua plugin but I get a plugin error when previewing an image file

ueberzug has exited unexpectedly.
It will be restarted on the next use.

even if ImageMagick is installed and vifm show the plugin as correctly loaded.

I would like to stick with kitty protocol because of the sensible image quality improvement over sixel. But while this is working correctly

fileviewer {*.png,*.jpg}
    \ kitten icat --silent --scale-up --place=%pwx%ph@%pxx%py %c >/dev/tty </dev/tty %N
    \ %pc
    \ kitten icat --silent --clear >/dev/tty </dev/tty %N

browsing a large image folder with preview became a lot slower and laggy, compared to the sixel solution; because of kitty protocol rendering I suppose?
In this scenario, do you think that could be helpful some sort of delay in the vifm preview when fast scrolling through image files, until the cursor stops for some time?

I would like to use chafa because I have my workflow streamlined around it and it's really a nice project. I don't mind use alternative, but my test have shown that even timg failed on vifm preview, what that could depends on?

And don't mind ghostty, while their project is promising I think it's still not enough battle tested, I will stick to kitty if I can migrate my setup from sixel to kitty.
Beside this thank you for helping me through the mess of terminal graphic protocol environment, really appreciated

by

ueberzug has exited unexpectedly.

You can check /tmp/ueberzugpp-$USER.log for some error information.

browsing a large image folder with preview became a lot slower and laggy, compared to the sixel solution; because of kitty protocol rendering I suppose?

Don't know if it's the protocol, its implementation, tmux or kitty. Can be one of those things or some unfortunate combination. %pd also caches output of a command within Vifm, although it may not have a significant effect with multiple images (can be tested by suppressing caching via %pu for sixel). You can try adding --transfer-mode=file or --transfer-mode=memory, in case auto-detection picks stream which is the slowest.

In this scenario, do you think that could be helpful some sort of delay in the vifm preview when fast scrolling through image files, until the cursor stops for some time?

Possibly, but setting this option would introduce a delay when not scrolling as well.

I would like to use chafa because I have my workflow streamlined around it and it's really a nice project. I don't mind use alternative, but my test have shown that even timg failed on vifm preview, what that could depends on?

Have you seen this comment on timg? The part about %N and </dev/tty. However, it doesn't seem to work inside tmux for me.

by

You can try adding --transfer-mode=file or --transfer-mode=memory,
in case auto-detection picks stream which is the slowest.

I confirm you it is picking stream, because it's the only of the three modes that works when forced, the other twos cannot display the image at all

Have you seen this comment on timg? The part about %N and
</dev/tty. However, it doesn't seem to work inside tmux for me.

I confirm that this fileviewer

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm,*.webp,*.svg} timg -p kitty -g%pwx%ph %c %pd %N </dev/tty

is working outside tmux (even if its not clearing the previous image), while inside it kinda works: still prints the image but is displaced all aroung, this is an example

by

I confirm you it is picking stream, because it's the only of the three modes that works when forced, the other twos cannot display the image at all

Unless you're previewing files from a remote machine or a different local user, all three methods should work.

I confirm that this fileviewer is working outside tmux (even if its not clearing the previous image), while inside it kinda works: still prints the image but is displaced all aroung, this is an example

Looks the same in my case. tmux seems to be handled by the code. timg, however, seems to only use "stream" format.

by
edited by

I tried again with ueberzugpp on a clean config and while it's not giving me tha errors, I cannot see the preview in vifm (is empty) even outside of tmux, while using kitty
- plugin is correctly installed and loaded (confirmed by :plugins menu)
- I can correctly open the generated ~/cache/vifm/ image files with a gui image viewer

these are the ueberzugpp logs

what can I try out to fix this?

edit: I noticed that ueberzugpp have this argument

-o,--output TEXT:{x11,wayland,sixel,kitty,iterm2,chafa}

and reading from logs seems it's defaulting to chafa.
From previous posted tests chafa/vifm/kitty stack was working with

fileviewer {*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm,*.webp,*.svg} chafa --size=%pwx%ph %c %pd

so I would expect that, using chafa, it should work through ueberzugpp too, at least outside tmux? or maybe an output method alternative to chafa can be forced in ueberzugpp plugin so it can work inside tmux too?

edit2: could be this the culprit? I'm on wayland kwin compositor

by

Oh, Wayland. chafa output won't work with the plugin because ueberzugpp runs in background and conflicts with Vifm, it's useful for drawing images on top of Windows.

chafa apparently only supports "stream" output for kitty protocol, so even if it did work, there would likely be a delay. I'm surprised "memory" and "file" don't work for you, is that true outside of Vifm as well?

by

I will gladly try again with memory/file transfer mode, what is the complete fileviewer I can try?

by

This one which was mentioned above:

fileviewer {*.png,*.jpg}
    \ kitten icat --silent --transfer-mode=file --scale-up --place=%pwx%ph@%pxx%py %c >/dev/tty </dev/tty %N
    \ %pc
    \ kitten icat --silent --clear >/dev/tty </dev/tty %N
by

oh that one, yeah it works only in stream mode both inside vifm with that fileviewer and outside vifm with this command

kitten icat --silent --transfer-mode=<mode> --scale-up ./cat.jpg

memory and file won't even work outside tmux for me

by
edited by

Then something must be broken in the setup. If even kitty's own implementation doesn't work as expected with kitty, given that file or memory is necessary to get rid of the delays no other third-party tool will likely work either. Need to debug what's going on. You could try checking how it works under a different user account to get a cleaner environment. Also, maybe kitten icat --detect-support will output something useful.

by

I think you helped me found the culprit: both shared memory and shared file transfer mode do not work across users because kitty enforces strict uid/gid matching on shared elements and a solution like
sudo -u $USER <command>
works (inside and outside vifm) if logged with root user but only outside of tmux, probably because even tmux is executed by root user?

I know running as root complicate the environment but do you think a workaround is feasible in this scenario?

by

Detection of tmux is done by checking for $TMUX environment variable which may not be preserved by sudo. You can try adding --passthrough tmux, however, this part of code may stand in the way: it seemingly disables not just detection but use of an explicitly requested memory or file transfer modes.

by

I decided to go the KISS route, and avoiding operating with a different user from the kitty process one, thank you for all <3

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...