aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-04-25 18:00:14 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-04-25 18:00:14 +0000
commit1d4e1b921d351da349ccfbc5d587489d7b77e690 (patch)
tree3d24c5352e25185361f3c8642db2024da1d10f73 /terminal.c
parentselection: add start/end coordinate getters (diff)
sixel/terminal: use the new grid and selection APIs
Use grid_row_abs_to_sb() instead of manually “rebasing” row numbers. Use selection_get_{start,end}() to retrieve the current selection coordinates.
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/terminal.c b/terminal.c
index f1b05f57..7d230cdf 100644
--- a/terminal.c
+++ b/terminal.c
@@ -2154,18 +2154,18 @@ term_erase(struct terminal *term, int start_row, int start_col,
void
term_erase_scrollback(struct terminal *term)
{
- const int num_rows = term->grid->num_rows;
+ const struct grid *grid = term->grid;
+ const int num_rows = grid->num_rows;
const int mask = num_rows - 1;
- const int start = (term->grid->offset + term->rows) & mask;
- const int end = (term->grid->offset - 1) & mask;
+ const int start = (grid->offset + term->rows) & mask;
+ const int end = (grid->offset - 1) & mask;
- const int scrollback_start = term->grid->offset + term->rows;
- const int rel_start = (start - scrollback_start + num_rows) & mask;
- const int rel_end = (end - scrollback_start + num_rows) & mask;
+ const int rel_start = grid_row_abs_to_sb(grid, term->rows, start);
+ const int rel_end = grid_row_abs_to_sb(grid, term->rows, end);
- const int sel_start = term->selection.coords.start.row;
- const int sel_end = term->selection.coords.end.row;
+ const int sel_start = selection_get_start(term).row;
+ const int sel_end = selection_get_end(term).row;
if (sel_end >= 0) {
/*
@@ -2183,8 +2183,8 @@ term_erase_scrollback(struct terminal *term)
* closer to the screen bottom.
*/
- const int rel_sel_start = (sel_start - scrollback_start + num_rows) & mask;
- const int rel_sel_end = (sel_end - scrollback_start + num_rows) & mask;
+ const int rel_sel_start = grid_row_abs_to_sb(grid, term->rows, sel_start);
+ const int rel_sel_end = grid_row_abs_to_sb(grid, term->rows, sel_end);
if ((rel_sel_start <= rel_start && rel_sel_end >= rel_start) ||
(rel_sel_start <= rel_end && rel_sel_end >= rel_end) ||
@@ -2196,8 +2196,9 @@ term_erase_scrollback(struct terminal *term)
tll_foreach(term->grid->sixel_images, it) {
struct sixel *six = &it->item;
- const int six_start = (six->pos.row - scrollback_start + num_rows) & mask;
- const int six_end = (six->pos.row + six->rows - 1 - scrollback_start + num_rows) & mask;
+ const int six_start = grid_row_abs_to_sb(grid, term->rows, six->pos.row);
+ const int six_end = grid_row_abs_to_sb(
+ grid, term->rows, six->pos.row + six->rows - 1);
if ((six_start <= rel_start && six_end >= rel_start) ||
(six_start <= rel_end && six_end >= rel_end) ||