aboutsummaryrefslogtreecommitdiff
path: root/sixel.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2023-06-16 14:20:37 +0000
committerDaniel Eklöf <daniel@ekloef.se>2023-06-24 05:31:02 +0000
commit66d9b8da604e4fd3aa6ee96da3609ff6b9896f50 (patch)
treeca1c0014cf7c44a24e061a1d2fe2acbc2b977ea5 /sixel.c
parentterm: scroll: only record scroll damage when viewport is at the bottom (diff)
sixel: fix cursor positioning logic
This adjusts the logic that positions the text cursor after emitting a sixel, when sixel scrolling mode is *enabled*. We’ve always mimicked XTerm’s behavior. However, XTerm recently changed its behavior, to better match that of an VT382. Now, the cursor is placed *on* the last row of the sixel, instead of on a new row after the sixel. This allows applications to print sixels to the bottom row of the terminal, without causing the content to scroll. Finally, there was a bug in the horizontal positioning of the cursor; it was placed on the *first* column of the row, instead of on the first column of the sixel.
Diffstat (limited to 'sixel.c')
-rw-r--r--sixel.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/sixel.c b/sixel.c
index 70ec2ee5..1af214a9 100644
--- a/sixel.c
+++ b/sixel.c
@@ -1043,6 +1043,23 @@ sixel_unhook(struct terminal *term)
pixel_rows_left -= height;
rows_avail -= image.rows;
+ if (do_scroll) {
+ /* Yes, truncate last row. This matches XTerm’s, and VT382’s behavior */
+ const int linefeed_count = image.height / term->cell_height;
+ for (size_t i = 0; i < linefeed_count; i++)
+ term_linefeed(term);
+
+ /* Position text cursor if this is the last image chunk */
+ if (rows_avail == 0) {
+ term_cursor_to(
+ term,
+ term->grid->cursor.point.row,
+ (term->sixel.cursor_right_of_graphics
+ ? min(image.pos.col + image.cols, term->cols - 1)
+ : image.pos.col));
+ }
+ }
+
/* Dirty touched cells, and scroll terminal content if necessary */
for (size_t i = 0; i < image.rows; i++) {
struct row *row = term->grid->rows[cur_row + i];
@@ -1055,26 +1072,6 @@ sixel_unhook(struct terminal *term)
row->cells[col].attrs.clean = 0;
}
- if (do_scroll) {
- /*
- * Linefeed, *unless* we're on the very last row of
- * the final image (not just this chunk) and private
- * mode 8452 (leave cursor at the right of graphics)
- * is enabled.
- */
- if (term->sixel.cursor_right_of_graphics &&
- rows_avail == 0 &&
- i >= image.rows - 1)
- {
- term_cursor_to(
- term,
- term->grid->cursor.point.row,
- min(image.pos.col + image.cols, term->cols - 1));
- } else {
- term_linefeed(term);
- term_carriage_return(term);
- }
- }
}
_sixel_overwrite_by_rectangle(