joshuto
joshuto copied to clipboard
[Feature requrest] libsixel support
I tried getting this to work with this script, adding img2sixel
manually, but when I hover over an image it gives me:
Failed to parse ansi colors: StackEmpty
Pq"1;1;1919;114#0;2;16;16;16#1;2;19;19;19#2;2; ...
Has anyone got sixel support to work? It would be good since it's Wayland ready and Uberzug is deprecated.
That is the same problem as with ueberzurg and ueberzurgpp I think. I got it kind of working (displaying images) by using a wrapper script and running the image preview function as a separate process before launching joshuto. (so the terminal cursor isn't confined by joshuto)
But I haven't fixed it a 100%, because somehow I can only get images by invoking the "shown" and "removed" functions from the general preview .sh file. My shown and removed "hooks" don't work (0.9.5). And apparently you really need to use the hooks because otherwise it will try to cache the preview and not work correctly when going back to an image.
Here is my work in progress wrapper script The "/dev/null" is really just a random variable name for removing images and not really /dev/null You can't share changing variables between different processes, that's why mkfifo is useful.
I'm using ayosec/alacritty (has sixel). https://github.com/ayosec/alacritty His work on sixel is basically finished, alacritty just hasn't pulled it. https://github.com/alacritty/alacritty/pull/4763
And with the printf statements disabling sixel scrolling (the image always starts at the top left of the screen, not where the cursor is. That seemed to help a bit, but really if I can get the hooks to work maybe that would not be needed (so you wouldn't have to edit the image differently with imagemagick for different resolutions). If you don't disable sixel scrolling you can just printf to a specific cursor location, for example
printf "\033[1:5H"
changes the cursor to the first line (yes starts from 1 not 0) and 5th to the right side from the top left.
Also I have no idea what the get_preview_meta_file() does, because it didn't look to me like it was ever called.
#!/usr/bin/env bash
pipe=/tmp/joshutopreviewpipe
rm -f $pipe
mkfifo $pipe
cursor()
{
printf "\033[?80h"
while [ -p $pipe ]
do
filepath=$(timeout 3 cat $pipe)
# timeout, so it stops blocking and quits on exit
# (blocks because of the fifo file when it's empty)
#
# could also get the pid and kill at the end
# I haven't really written ctrl+c etc traps yet (so it would always exit nicely)
#
if [ -n "$filepath" ]
then
if [[ "$filepath" == "/dev/null" ]]
then
magick -size 1280x720 canvas:transparent jpg:- | img2sixel --static --quality=low --encode-policy=size
else
magick "$filepath" -scale 400x -gravity east -background transparent -extent 1280x720 jpg:- | img2sixel --static --quality=low --encode-policy=size
unset filepath
# yes magick can convert to sixel, but img2sixel is faster
fi
fi
done
printf "\033[?80l"
}
show_image()
{
echo "huh"
echo "$1" > /tmp/joshutopreviewpipe
# this function apparently does not have access to $pipe
}
remove_image()
{
echo "/dev/null" > /tmp/joshutopreviewpipe
}
get_preview_meta_file()
{
echo "$joshuto_wrap_preview_meta/$(echo "$1" | md5sum | sed 's/ //g')"
}
export -f get_preview_meta_file
export -f show_image
export -f remove_image
cursor &
joshuto "$@"
rm -f $pipe
"My shown and removed "hooks" don't work (0.9.5 binary release)." It just shows nothing. (my images and previews "work" if I put it directly in the general preview .sh file, so it must be some really simple problem on my end)
I'm thinking of giving up because of this, because I don't want to use random older versions to see if the documentation will work for those. I don't write or read any rust. I literally copied the hooks from the documentation and those don't work even when my image functions (which I saw working when put in the general preview .sh file) are replaced with echo commands that should just print something on the preview location.
If someone could help me with that, that would be nice.
I could just fix this in a couple of hours if I knew how to get the hooks to work (and work "consistently", so the drawing time is right and doesn't mess things up while sixel scrolling is enabled). (sixel scrolling enabled means it draws where the cursor is and not from the top left of the terminal)
Seems like there is a substantial amount of people that would want this feature. So I will look into it as soon as I have more time available :+1:
When it's working, I'll add it to nix home-manager at some point as a configuration option.
wonder this too.