Search code examples
terminal

Displaying a sixel image in a terminal without a line break afterwards


I would like to display an image in a terminal inline, without a line break afterwards. I came across the Sixel format, but all examples I've found move the cursor to the next line after the image is displayed.

% cat hi.sixel; echo rest
(sixel image here)
rest
%

Using the script from Sixel Demo:

#!/bin/sh
echo
echo
echo
echo -n before
printf 'G1BxIzA7MjswOzA7MCMxOzI7MTAwOzEwMDswIzI7MjswOzEwMDswIzF+fkBAdnZAQH5+QEB+fiQjMj8/fX1HR319Pz99fT8/LSMxITE0QBtcCg==' | base64 -d
echo -n after
echo
echo
echo

I get the following output (note an extra blank line between sixel and "after"):

"before" printed on the same line as the sixel, but "after" is on the line after next

  • Is this behavior specified by the Sixel standard?
  • How can I display a sixel image inline, like this?
% cat hi.sixel; echo rest
(sixel image here)rest
%

Solution

  • This is possible (assuming the terminal supports it) by first emitting the ESC [?8452h control sequence.

    echo -ne "\033[?8452h" && cat image.sixel && echo "<-- Bottom-Right"
    

    See: