hpjansson / chafa

📺🗿 Terminal graphics for the 21st century.
https://hpjansson.org/chafa/
GNU Lesser General Public License v3.0
2.87k stars 60 forks source link

xterm sixel support not detected automatically #191

Open ploum opened 8 months ago

ploum commented 8 months ago

using xterm 384 with xterm -ti vt340

happening: chafa picture.jpg return pictures in symbols. chafa -f sixels picture.jpg returns pictures in sixels (perfect quality)

expected: with "-f sixels", chafa should recognize sixels support and use sixels by default

ploum commented 8 months ago

Oops, realized afterward that this was with chafa 1.12. Will test with 1.14 later.

hpjansson commented 8 months ago

I think the situation is the same in 1.14. XTerm used to default to having sixel support turned off - you had to enable VT340 support in order to get it, and I couldn't find a way to passively detect when this was the case. It looks like newer XTerm has it turned on. Do you know in which version this was changed, and how old it is?

ploum commented 8 months ago

On 24/02/08 11:17, Hans Petter Jansson wrote:

I think the situation is the same in 1.14. XTerm used to default to having sixel support turned off - you had to enable VT340 support in order to get it, and I couldn't find a way to passively detect when this was the case. It looks like newer XTerm has it turned on. Do you know in which version this was changed, and how old it is?

I had no idea it was turned on by default.

But there’s a very interesting detection mechanism in the lsix project, which seems to check for a reply code of "4" to the vt220 escape sequence (no, I don’t understand how it works)

# IS TERMINAL SIXEL CAPABLE?        # Send Device Attributes
IFS=";?c" read -a REPLY -s -t 1 -d "c" -p $'\e[c' >&2
for code in "${REPLY[@]}"; do
if [[ $code == "4" ]]; then
     hassixel=yup
     break
fi
done

# YAFT is vt102 compatible, cannot respond to vt220 escape sequence.
if [[ "$TERM" == yaft* ]]; then hassixel=yeah; fi

Please note that this only works with bash, not in zsh (which may use the POSIX read version without all those options).

hpjansson commented 8 months ago

Looks like I was wrong about XTerm enabling support by default. xterm -ti vt340 seems to be required still on xterm-389. lsix is actively probing the terminal, which we're not yet doing (and which when implemented may still not work in all situations, like when we can't access the controlling terminal).

So the action item here is to implement active probing. I put some of the scaffolding in place in Chafa 1.14, so it may not be that far away.

j4james commented 7 months ago

@hpjansson FYI, you can enable the graphics protocols in XTerm without "downgrading" to VT340 by setting the decGraphicsID resource. That's been an option since patch 357 if the logs are accurate.