Skip to content

Commit 5bddfe0

Browse files
author
Anna Blake
committed
Detect non-sixel capable terminals and exit with an error
Uses the Send Device Attribute control sequence $'\e[c' to find what features are supported. Feature "4" means SIXEL. https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Sixel-Graphics
1 parent 0f4cd2e commit 5bddfe0

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lsix

+17-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Requirements: just ImageMagick (and a Sixel terminal, of course)
77

8-
# Version 1.6.1
8+
# Version 1.6.2
99
# B9 December 2018
1010

1111
# See end of file for USAGE.
@@ -61,12 +61,27 @@ autodetect() {
6161
# Don't show escape sequences the terminal doesn't understand.
6262
stty -echo # Hush-a Mandara Ni Pari
6363

64+
# IS TERMINAL SIXEL CAPABLE?
65+
read -s -t 1 -d "c" -p $'\e[c' >&2 # Send Device Attributes
66+
if ! [[ $REPLY =~ ";4;" ]]; then
67+
cat <<-EOF >&2
68+
Error: Your terminal does not appear to support sixel graphics.
69+
70+
Please use a sixel capable terminal, such as xterm -ti vt340, or
71+
ask your terminal manufacturer to add sixel support.
72+
73+
If your terminal actually does support sixel, please file a bug
74+
report at http://github.com/hackerb9/lsix/issues
75+
EOF
76+
exit 1
77+
fi
78+
6479
# TERMINAL COLOR AUTODETECTION.
6580
# Find out how many color registers the terminal has
6681
IFS=";" read -a REPLY -s -t ${timeout} -d "S" -p $'\e[?1;1;0S' >&2
6782
[[ ${REPLY[1]} == "0" ]] && numcolors=${REPLY[2]}
6883

69-
# BUG WORKAROUND: mlterm does not report number of colors.
84+
# Bug workaround: mlterm does not report number of colors.
7085
if [[ $TERM =~ mlterm ]]; then numcolors=1024; fi
7186

7287
# Increase colors, if needed

0 commit comments

Comments
 (0)