Skip to content

Commit

Permalink
Handle bug in ImageMagick (Graphic Newline at end of image)
Browse files Browse the repository at this point in the history
ImageMagick sends '-' (graphic newline in sixels) before the string
terminator (ESC \). It should not. We work around it by piping the
output of convert into sed.
  • Loading branch information
hackerb9 committed Mar 30, 2024
1 parent 2091123 commit fe801f6
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions vv
Original file line number Diff line number Diff line change
Expand Up @@ -1184,10 +1184,10 @@ fakefile() {
showimage() {
# Shows the file named in $1 using sixel.

# Global variable $viewmode is either "full", which enlarges it to
# the full size of the terminal window, or it is "fast", which
# scales the image down, removes colors, and takes other shortcuts
# for the fastest preview.
# Global variable $viewmode is (usually) either "full", which
# enlarges it to the full size of the terminal window, or it is
# "fast", which scales the image down, removes colors, and takes
# other shortcuts for the fastest preview.

# Note that "full size" is not exactly the same as "full screen".
# In a terminal emulator, the sixel graphics are just a window.
Expand Down Expand Up @@ -1319,7 +1319,8 @@ showimage() {
esac
tput el
if [[ "$output" ]]; then
echo -n "$output"
local ST=$'\e\\\\' # String Terminator is Esc \.
echo -n "$output" | sed "s/-${ST}/${ST}\n/g" # (sed kludge for bug in IM 6.9.12)
SHOULDREDRAW="" # Reset redraw flag until SIGWINCH trips it
else
# Error. ImageMagick must have failed as $output is empty.
Expand Down Expand Up @@ -1814,12 +1815,14 @@ dotfordot() {


### Show pieces
local ST=$'\e\\\\' # String Terminator is Esc \.
local IFS=$'\n'
for f in $(ls -1v $tmpdir/*crop.ppm); do
echo -en "$f\r"
convert "$f" "$f.sixel"
cat "$f.sixel"
done
cat "$f.sixel" | sed "s/-${ST}/${ST}\n/g" # (sed kludge for bug in IM 6.9.12)
done


### All done
rm $tmpdir/*crop.*
Expand Down

0 comments on commit fe801f6

Please sign in to comment.