chafa icon indicating copy to clipboard operation
chafa copied to clipboard

sixels: last line cut/truncated on terminal emulators with "correct" text cursor placement

Open dnkl opened this issue 4 months ago • 61 comments

Sixel capable terminal emulators have gotten cursor placement (after emitting the sixel) wrong since the beginning. They usually put the cursor on a new line under the sixel. This means the terminal content may scroll, if a sixel is printed on the last row.

However, it's not how the VT340 did it. The simplified explanation is that it places the cursor on the last line of the sixel. Thus, if you want to print text under the sixel, you first have to print a newline.

The real algorithm is slightly more complex than that. A sixel is 6 pixels tall. This means it can cover two text rows. The DEC cursor placement algorithm puts the text cursor where the top pixel is. This means there are times when two newlines are required to print text under the sixel.

A number of terminals have started to implement the correct behavior. Terminals that implement the DEC placement algorithm are foot, contour, DomTerm and WezTerm. There may be more that I'm not aware of. XTerm is close to correct, but last time I checked, it placed the cursor on the bottom pixel (i.e. you always need a single newline).

Right now, running chafa <image> && echo "XXXXXX" will look something like this in e.g. foot:

chafa-last-line-cut (picture shows a part of my dog's paw...)

A bit more information here:

  • https://github.com/contour-terminal/contour/pull/825#issuecomment-1256607524
  • https://github.com/hackerb9/vt340test/issues/25
  • https://github.com/hackerb9/lsix/pull/51

dnkl avatar Feb 29 '24 09:02 dnkl