Suckless st regrind
April 19, 2023 —
shinohai
This is just a redo of the original st vpatch with a tweak that allows drawing of images directly to the terminal. Much like the patch listed in the st FAQ this version does not cancel double-buffering, thereby doing away with the flickering that I observed when I first tried this. While not perfect, it does render images well with w3m for me, and by abusing the w3m image display doubles as a simple image viewer with a little bash-foo. Here's how you do that:
#!/bin/bash
if [ -z $1 ]; then
echo
echo "USAGE: timg "
echo
exit 0;
fi
W3MIMGDISPLAY="/usr/local/bin/w3mimgdisplay"
FILENAME=$1
FONTH=14
FONTW=8
COLUMNS=`tput cols`
LINES=`tput lines`
read width height <<< `echo -e "5;$FILENAME" | $W3MIMGDISPLAY`
max_width=$(($FONTW * $COLUMNS))
max_height=$(($FONTH * $(($LINES - 2))))
if test $width -gt $max_width; then
height=$(($height * $max_width / $width))
width=$max_width
fi
if test $height -gt $max_height; then
width=$(($width * $max_height / $height))
height=$max_height
fi
w3m_command="0;1;0;0;$width;$height;;;;;$FILENAME\n4;\n3;"
tput cup $(($height/$FONTH)) 0
echo -e $w3m_command|$W3MIMGDISPLAY
