diff options
| -rw-r--r-- | sixel.c | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -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 */ |
