From b70f0468e267f07635ab2e933a2b627d194bfa6f Mon Sep 17 00:00:00 2001 From: b9 Date: Fri, 17 Sep 2021 19:03:46 -0700 Subject: [PATCH 1/2] Work around sixel cursor placement bug Most sixel compatible terminal emulators do not yet correctly place the text cursor on the final line of sixel image data (the upper row if straddling two lines of text) after a sixel image has been transmitted. --- lsix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lsix b/lsix index 54fced3..ae1cb9a 100755 --- a/lsix +++ b/lsix @@ -120,6 +120,19 @@ autodetect() { # SIXEL SCROLLING (~DECSDM) is now presumed to be enabled. # See https://github.com/hackerb9/lsix/issues/41 for details. + # SIXEL CURSOR PLACEMENT BUG WORKAROUND + case "$TERM" in + vt340*|contour*) + # These terminals are correct. + sixelcursorbug="" + ;; + xterm*|mlterm|yaft*|*) + # These terminals have not yet been fixed. + sixelcursorbug="-n" + ;; + esac + + # TERMINAL COLOR AUTODETECTION. # Find out how many color registers the terminal has IFS=";" read -a REPLY -s -t ${timeout} -d "S" -p $'\e[?1;1;0S' >&2 @@ -243,6 +256,8 @@ main() { done montage "${onerow[@]}" $imoptions gif:- \ | convert - -colors $numcolors sixel:- + + echo $sixelcursorbug # Go to next line, unless terminal is quirky. done } From 32fbde6d1cbb0898560cc2585356c0565d2a6b51 Mon Sep 17 00:00:00 2001 From: b9 Date: Fri, 17 Sep 2021 19:34:36 -0700 Subject: [PATCH 2/2] Remove erroneous graphics newline from montage montage always generates a '-' at the end of a sixel image. As pointed out by @j4james, this should not happen by default. Until ImageMagick fixes the bug (which may require an update to libsixel), we can easily remove the offending character using bash. Lsix will continue to work either way. --- lsix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lsix b/lsix index ae1cb9a..a621c57 100755 --- a/lsix +++ b/lsix @@ -127,12 +127,11 @@ autodetect() { sixelcursorbug="" ;; xterm*|mlterm|yaft*|*) - # These terminals have not yet been fixed. + # These terminals have not yet been fixed. Use -n for echo. sixelcursorbug="-n" ;; esac - # TERMINAL COLOR AUTODETECTION. # Find out how many color registers the terminal has IFS=";" read -a REPLY -s -t ${timeout} -d "S" -p $'\e[?1;1;0S' >&2 @@ -254,10 +253,15 @@ main() { onerow[len++]="file://$1" shift done - montage "${onerow[@]}" $imoptions gif:- \ - | convert - -colors $numcolors sixel:- + output=$(montage "${onerow[@]}" $imoptions gif:- \ + | convert - -colors $numcolors sixel:-) + + # Workaround bug in ImageMagick that erroneously sends a + # graphics newline (-) before the end of the image (Esc backslash). + output=${output%-??}$'\e\\' - echo $sixelcursorbug # Go to next line, unless terminal is quirky. + # Go to next line, unless terminal is quirky. + echo $sixelcursorbug "$output" done }