kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.15k stars 972 forks source link

Image Preview vifm #1308

Closed JohnJohnstone closed 5 years ago

JohnJohnstone commented 5 years ago

Hi @kovidgoyal, I'm having an issue with previewing images inside vifm using the --place option. I am able to use kitty +kitten icat filename without any issue but when i use the place option i get the error "The --place option can only be used with a single image". I have written a few differenct scripts attempting to address the issue i am certain that only one filename is being passed. My solution was to comment out the if statement in the icat kitten and now image preview works as expected.

https://github.com/kovidgoyal/kitty/blob/master/kittens/icat/main.py#L309

   ``` if len(items) > 1 or (isinstance(items[0], str) and os.path.isdir(items[0])):
        raise SystemExit('The --place option can only be used with a single image')```

Thank you for your efforts with this great terminal emulator :)

kovidgoyal commented 5 years ago

I dont see anything wrong with the code and running

kitty +kitten icat --place 10x10@0x0 resources/images/lt.png

works as expected. I need some way to reproduce the problem you are having.

andpalmier commented 5 years ago

I am not sure I am in the right place to post this, but I tried to do the same. I managed to preview the file without issues, but the clear option does not work as expected. I added in the vifmrc this:

fileviewer *.jpg,*.jpeg,*png,
    \ kitty icat --place=%pwx%ph@%pxx%py %c 
    \ %pc
    \ kitty icat --clear

It seems like the left part of the screen of vifm moves down at every refresh.

kovidgoyal commented 5 years ago

I doubt this has anything to do with icat or kitty. icat --clear simply sends a graphics command to delete all images, it does not affect the scroll position in any way. As you can test by running it yourself. The only exception is if you run it and also provide some images, in which case those images will be displayed after the clear and without --place, displaying images causes scrolling.

kovidgoyal commented 5 years ago

As for the original issue, the problem is that vifm set the stdin of the filviewer program to null instead of the terminal, which breaks icat. I have added a --stdin option to icat to tell it not to try to read images from stding to workaround that. As fo rthe screen moveing after icat, I have no idea, you will need to ask the vifm developers.

p-kolacz commented 5 years ago

@andpalmier try this

fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm
           \ kitty icat --transfer-mode=file --place=%pwx%ph@%pxx%py %c
           \ %pc
           \ kitty icat --transfer-mode=file --clear

The problem is that icat sends "Detecting..." to stdout which breaks vifm. Setting --transfer-mode disable detection.

kovidgoyal commented 5 years ago

I have added --silent to icat

andpalmier commented 5 years ago

Thanks, now i do not have my Mac anymore, so I cannot test it there.

folliehiyuki commented 4 years ago

Hi. Is reopening this issue alright? I only moved to vifm recently and got this issue: whenever I turn view mode off then on again the terminal "freaks out" and throws stuff onto the screen endlessly. My setting for previewing is like this:

fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm
               \ kitty icat --silent --place=%pwx%ph@%pxx%py %c
               \ %pc
               \ kitty icat --silent --clear

I can work around this by creating a command to manually do kitty icat --clear instead of putting it into the preview command, but it leaves behind a black frame like this screen2 My system info:

GeorgeHJ commented 3 years ago

Hi @FollieHiyuki, in case it's useful.

Have you tried using the %pd macro? I just gave it a go and it works for me albeit a little slowly.

From the docs, here:

  %pd   Marks a preview command as one that directly communicates with the terminal. Beware that this is for things like sixel which are self-contained sequences that depend only on current cursor position, using this with anything else is likely to mangle terminal state.
fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm
\ kitty +icat --place %pwx%ph@%pxx%py  --silent %c
\ %pc
\ kitty icat --clear --silent %pd
folliehiyuki commented 3 years ago

Thanks @GeorgeHJ that does fix the issue

LamprosPitsillos commented 3 years ago

Using the exact snippet that @GeorgeHJ gave above , i get this error.

Traceback (most recent call last):                                                           
    File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main                       
    return _run_code(code, main_globals, None,                                               
            File "/usr/lib/python3.9/runpy.py", line 87, in _run_code                                  
            exec(code, run_globals)                                                                  
            File "/usr/bin/../lib/kitty/__main__.py", line 153, in <module>                            
            main()                                                                                   
            File "/usr/bin/../lib/kitty/__main__.py", line 144, in main                                
            namespaced(['+', first_arg[1:]] + sys.argv[2:])                                          
            File "/usr/bin/../lib/kitty/__main__.py", line 99, in namespaced                           
            func(args[1:])                                                                           
            File "/usr/bin/../lib/kitty/__main__.py", line 13, in icat                                 
            rk('icat')                                                                               
            File "/usr/bin/../lib/kitty/kittens/runner.py", line 122, in run_kitten                    
            runpy.run_module('kittens.{}.main'.format(kitten), run_name=run_name)                    
            File "/usr/lib/python3.9/runpy.py", line 213, in run_module                                
            return _run_code(code, {}, init_globals, run_name, mod_spec)                             
            File "/usr/lib/python3.9/runpy.py", line 87, in _run_code                                  
            exec(code, run_globals)                                                                  
            File "/usr/bin/../lib/kitty/kittens/icat/main.py", line 583, in <module>                   
            main()                                                                                   
            File "/usr/bin/../lib/kitty/kittens/icat/main.py", line 507, in main                       
            sys.stdout = open(os.ctermid(), 'w')                                                     
    OSError: [Errno 6] No such device or address: '/dev/tty' 

Info

Kitty: kitty 0.23.1 Vifm:

Version: 0.12
Git info: built out of repository
Compiled at: Oct  3 2021 09:59:56

Support of extended keys is on
Parsing of .desktop files is enabled
Without GTK+ library
With magic library
Without X11 library
Without dynamic loading of X11 library
With file program
With -n option for cp and mv
With remote command execution

Os: Artix Linux

hutou commented 2 years ago

Hi, Exactly same error for me (running on Archlinux)

Danielgb23 commented 2 years ago

Same here. Exact same error running:

filetype *.bmp,*.jpg,*.jpeg,*.png,*.xpm open -a Preview %f &
fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.xpm
    \ kitty +kitten icat --clear --transfer-mode=file --place=%pwx%ph@%pxx%py %c
    \ %pc
    \ kitty +kitten icat --transfer-mode=file --place=%pwx%ph@%pxx%py --clear
cd-a commented 2 years ago

same issue on macOS

edit: https://github.com/vifm/vifm/issues/731 has a fix

akhiljalagam commented 7 months ago

@andpalmier try this

fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm
         \ kitty icat --transfer-mode=file --place=%pwx%ph@%pxx%py %c
         \ %pc
         \ kitty icat --transfer-mode=file --clear

The problem is that icat sends "Detecting..." to stdout which breaks vifm. Setting --transfer-mode disable detection.

Does it store the image in cache to save CPU resources for large images? ranger-fm works like this.