kovidgoyal / kitty

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

Bug with icat kitten "No decode delegate" "--place can only be used with one image, not 2" despite there only being one valid image path #6430

Closed sweetbbak closed 1 year ago

sweetbbak commented 1 year ago

The bug

I'm getting these few errors when using kitty +kitten icat inside of a bash script that say that it cant decode the image, find the path of the image, or cannot use place with "2 images."

Despite these errors, there is only one path. The path is also valid. I think it is reading some kind of character at the end of the string as a separate path, but no matter what I try I haven't been able to fix this issue. It will spit out an error and refuse to show the image, but manually copying the path and using icat works perfectly fine.

/home/sweet/ssd/gallery-dl/twitter/ukasanagi_/1554343762834231296_1.jpg Error: The --place option can only be used with a single image, not 2 Manually copying the path, works however and the image is show without any issue.

/home/sweet/ssd/gallery-dl/twitter/ukasanagi_/15979832952294821.jpg Error: Stat /home/sweet/ssd/gallery-dl/twitter/ukasanagi/15979832952294821.jpg: stat /home/sweet/ssd/gallery-dl/twitter/ukasanagi/1597983295229482_1.jpg: no such file or directory

The Output of running the same string through "od -c" in the same script /home/sweet/ssd/gallery-dl/twitter/ukasanagi_/1653346451647528961_1.jpg

0000000 / h o m e / s w e e t / s s d / 0000020 g a l l e r y - d l / t w i t t 0000040 e r / u k a s a n a g i / 1 6 0000060 5 3 3 4 6 4 5 1 6 4 7 5 2 8 9 6 0000100 1 1 . j p g \n 0000110 Error: The --place option can only be used with a single image, not 2

You may note the '\n' character at the end of the string there

To Reproduce Steps to reproduce the behavior: run: bash -c 'mapfile array < <(find ~ -type f ( -iname *.jpg -o -iname *.png -iname *.gif ) ) && for x in "${array[@]}"; do kitty +kitten icat --scale-up --place 33x33@0x0 "${x}" ; sleep 1 ; done'

and run to see what the shell is "seeing" the string as: copy and pasting this will likely remove the backslashes around (iname ... .gif ) - they need to be there. bash -c 'mapfile array < <(find ~ -type f ( -iname *.jpg -o -iname *.png -iname \.gif ) ) && for x in "${array[@]}"; do echo "${x}" | od -c ; kitty +kitten icat --scale-up --place 33x33@0x0 "${x}" ; sleep 1 ; done'

this also happens with bash builtin readarray.

So far I've tried every suggested way to remove non-printable characters in a variety of different ways to see if this will fix the issue but it hasn't. The output of od -c had me convinced that removing the newline character would fix the issue but no matter what I try it doesn't work.

    image=$(realpath -- "${image}")
    image="$(echo "${image}" | tr -d '\n' | tr -d '\n\r' | tr -d '\012'  | sed -e 's/\n//g' -e 's/\0//g' | tr -dc "[:print:]" )"

Environment details

kitty 0.28.1 created by Kovid Goyal
Linux sweet-chaos 6.4.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 06 Jul 2023 18:35:54 +0000 x86_64
EndeavourOS Linux 6.4.2-arch1-1 (/dev/tty)

DISTRIB_ID=EndeavourOS
DISTRIB_RELEASE="rolling"
DISTRIB_DESCRIPTION="EndeavourOS Linux"
DISTRIB_CODENAME=rolling
Running under: Wayland
Frozen: False
Paths:
  kitty: /usr/bin/kitty
  base dir: /usr/lib/kitty
  extensions dir: /usr/lib/kitty/kitty
  system shell: /bin/zsh
Loaded config files:
  /home/sweet/.config/kitty/kitty.conf

Config options different from defaults:
allow_remote_control    yes
background_image_layout scaled
background_tint         0.9
confirm_os_window_close 0
cursor_shape            2
dim_opacity             0
editor                  code
enable_audio_bell       False
font_family             Maple Mono
listen_on               unix:/tmp/kitty
modify_font:
    baseline 0
    underline_position 1
    underline_thickness 1
resize_in_steps         True
window_padding_width    FloatEdges(left=3.0, top=3.0, right=3.0, bottom=3.0)
Added shortcuts:
    ctrl+alt+enter →  launch --cwd=current
    f1 →  launch --stdin-source=@screen_scrollback --stdin-add-formatting less +G -R
    kitty_mod+y →  new_window less @selection
Colors:
    background              #121212   
    color0                  #1b1d1e   
    color1                  #ff87d7   
    color10                 #008787   
    color11                 #fdfd8a   
    color12                 #5f5fff   
    color13                 #9e6ffe   
    color14                 #a3babf   
    color15                 #f8f8f2   
    color2                  #008787   
    color3                  #fd971f   
    color4                  #5f5fff   
    color5                  #9e6ffe   
    color6                  #5e7175   
    color7                  #ccccc6   
    color8                  #505354   
    color9                  #ff87d7   
    cursor                  #bbbbbb   
    foreground              #e0dfe0   
    selection_background    #453a39   
    selection_foreground    #121212   

Important environment variables seen by the kitty process:
    PATH                                /usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/home/sweet/.dotnet/tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin
    LANG                                en_US.UTF-8
    EDITOR                              nano
    SHELL                               /bin/zsh
    DISPLAY                             :0
    WAYLAND_DISPLAY                     wayland-1
    USER                                sweet
    XCURSOR_SIZE                        22
    XDG_SESSION_PATH                    /org/freedesktop/DisplayManager/Session0
    XDG_BACKEND                         wayland
    LC_ADDRESS                          en_US.UTF-8
    LC_NAME                             en_US.UTF-8
    LC_MONETARY                         en_US.UTF-8
    XDG_SEAT                            seat0
    XDG_SESSION_DESKTOP                 hyprland
    XDG_SESSION_TYPE                    wayland
    XDG_GREETER_DATA_DIR                /var/lib/lightdm-data/sweet
    LC_PAPER                            en_US.UTF-8
    XDG_CURRENT_DESKTOP                 Hyprland
    XDG_SEAT_PATH                       /org/freedesktop/DisplayManager/Seat0
    XDG_SESSION_CLASS                   user
    LC_IDENTIFICATION                   en_US.UTF-8
    LC_TELEPHONE                        en_US.UTF-8
    LC_MEASUREMENT                      en_US.UTF-8
    XDG_VTNR                            7
    XDG_SESSION_ID                      1
    XDG_RUNTIME_DIR                     /run/user/1000
    LC_TIME                             en_US.UTF-8
    LC_NUMERIC                          en_US.UTF-8

Additional context Any help is appreciated, I think this might be some kind of encoding error, or an error from some obscure null/escape character being read as a path.

kovidgoyal commented 1 year ago

I dont follow how this is an issue with the kitten? If you pass it paths with newlines at the end, then it will use them, it is not going to second guess the intentions of its invoker.

sweetbbak commented 1 year ago

I don't know where the newline character is coming from, it shouldn't be there at all. There is no way to remove it. If something I was doing was somehow adding a newline character to the end of the string, then I would suspect that it should be able to be removed using sed 's/\n//g' and tr -d '\n' or bash expansion, but it can't.

kovidgoyal commented 1 year ago

Here you go

mapfile array < <(find . -type f -iname '*.png')
image=$(printf "%s" "${array[0]}")
kitten icat --scale-up --place 33x33@0x0 "$image"

I suggest you learn a bit more about BASH scripting, or better use a nicer script language Just FYI, you have python available everywhere you have kitty available, with kitty +runpy and kitty +launch.

sweetbbak commented 1 year ago

I probably should just use a better language because its frustrating that this works perfectly well in a vacuum but when I substitute it into my script that is reading the image paths from a pipe like "find . -type f -iname '*.png' | ./myscript | xargs echo " it no longer behaves as expected. image

Thank you for your time.