mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
sixel: insert: calculate end rows in a single statement
This commit is contained in:
parent
4a0042ba15
commit
0483466f68
1 changed files with 21 additions and 8 deletions
29
sixel.c
29
sixel.c
|
|
@ -93,23 +93,36 @@ sixel_insert(struct terminal *term, struct sixel sixel)
|
|||
const int scrollback_end
|
||||
= (term->grid->offset + term->rows) & (term->grid->num_rows - 1);
|
||||
|
||||
int end_row = sixel.pos.row + sixel.rows - scrollback_end;
|
||||
while (end_row < 0)
|
||||
end_row += term->grid->num_rows;
|
||||
const int end_row
|
||||
= (sixel.pos.row + sixel.rows
|
||||
- scrollback_end
|
||||
+ term->grid->num_rows) & (term->grid->num_rows - 1);
|
||||
assert(end_row >= 0 && end_row < term->grid->num_rows);
|
||||
|
||||
tll_foreach(term->grid->sixel_images, it) {
|
||||
int e = it->item.pos.row + it->item.rows - scrollback_end;
|
||||
e -= scrollback_end;
|
||||
while (e < 0)
|
||||
e += term->grid->num_rows;
|
||||
const int e
|
||||
= (it->item.pos.row + it->item.rows
|
||||
- scrollback_end
|
||||
+ term->grid->num_rows) & (term->grid->num_rows - 1);
|
||||
assert(e >= 0 && e < term->grid->num_rows);
|
||||
|
||||
if (e < end_row) {
|
||||
tll_insert_before(term->grid->sixel_images, it, sixel);
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
tll_push_back(term->grid->sixel_images, sixel);
|
||||
|
||||
out:
|
||||
#if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG
|
||||
LOG_DBG("sixel list after insertion:");
|
||||
tll_foreach(term->grid->sixel_images, it) {
|
||||
LOG_DBG(" rows=%d+%d", it->item.pos.row, it->item.rows);
|
||||
}
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Row numbers are absolute */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue