The state after this function is an intermediate state and isn’t
necessarily valid.
This sixels needs to be ‘reflowed’ to ensure a valid state. This is
something that should be done by the caller after the text grid has
been reflowed and the sixel coordinates have been re-mapped to the new
grid.
TODO: can/should we update the sixel cols/rows in sixel_reflow()
instead?
This function loops the list of sixels, and discards those that would
be scrolled out if the grid offset is moved forward by the specified
number of rows.
The criteria is when the rebased row value is less than the number of
rows to scroll.
A rebased row number is a zero-based number starting at the beginning
of the scrollback. Thus, when scrolling 5 rows, rows with a rebased
row number between 0-4 will be scrolled out.
For performance reasons, we used to break out of the loop as soon as a
row number *larger* than the scroll count.
This however does not work. The sixels are sorted by their *end*
row. While this works in most cases (think images outputted in the
shell in the normal screen), it doesn’t always.
In the alt screen, where applications can print images just about
anywhere, it is possible to have *any* start row number anywhere in
the sixel list. Just as long as their *end* row numbers are sorted.
For example, a huuuge sixel that covers the entire scrollback. This
sixel will naturally be first in the list (and thus sixel_scroll_up()
will visit it *last*, since it iterates the list in reverse), but
should still be destroyed when scrolling.
Move sixel reflow from grid_reflow() to sixel_reflow(). This lets us
use internal sixel functions to update the sixels.
Note that grid_reflow() still needs to remap the sixelss coordinates.
When a sixel image crosses the scrollback wrap-around, it is split up
into (at least) two pieces.
We use cursor->point.col for all pieces’ x-coordinate. This caused the
final image to appear sheared, since we do a carriage-return (after a
number of linefeeds) after each piece - this causes the cursor’s
position to be reset to the left margin.
The solution is simple; remember the cursor’s initial x-coordinate,
and use that to position all image pieces.
Closes#151.
This fixes a crash when the emitted sixel extends beyond the right
margin. The crash only happens when there are other sixel images
already emitted.
Fixes part of #151
When copying the image data for the left and right parts of the
splitted images, use the sixel's height, not the cell height.
This fixes a crash when the sixel didn't cover the entire cell height.
The logic that breaks out of sixel loops does not work for rows that
has already wrapped around.
Thus, we need to destroy sixels that are about to be scrolled
out *before* we actually scroll.
Since this is the *only* time we destroy sixels (instead of
overwriting it), rename the sixel functions. And, since they now do a
very specific thing, they can be greatly simplified (and thus faster).
If changing the font size causes the cell size to decrease, either
horizontally or vertically (or both), then delete all sixels since the
grid space they allocated no longer is enough to hold the images.
Since the images are sorted, we can break out of the loop as soon as
we detect an image that *ends before* the rectangle's top starts.
In order for the row comparisons to work, the row numbers must be
re-based against the current scrollback offset, or the
scrollback *end*, to be precise.
Since the images are sorted, we can break out of the loop as soon as
we detect an image that *ends before* the row we're looking for.
In order for the row comparisons to work, the row numbers must be
re-based against the current scrollback offset, or the
scrollback *end*, to be precise.