Merge branch 'term-erase-refactor'

This commit is contained in:
Daniel Eklöf 2021-12-26 12:42:05 +01:00
commit 323f645bb2
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 52 additions and 49 deletions

68
csi.c
View file

@ -339,10 +339,7 @@ decset_decrst(struct terminal *term, unsigned param, bool enable)
if (enable) if (enable)
LOG_WARN("unimplemented: 132 column mode (DECCOLM)"); LOG_WARN("unimplemented: 132 column mode (DECCOLM)");
term_erase( term_erase(term, 0, 0, term->rows - 1, term->cols - 1);
term,
&(struct coord){0, 0},
&(struct coord){term->cols - 1, term->rows - 1});
term_cursor_home(term); term_cursor_home(term);
break; break;
@ -512,10 +509,7 @@ decset_decrst(struct terminal *term, unsigned param, bool enable)
min(term->normal.cursor.point.col, term->cols - 1)); min(term->normal.cursor.point.col, term->cols - 1));
tll_free(term->normal.scroll_damage); tll_free(term->normal.scroll_damage);
term_erase( term_erase(term, 0, 0, term->rows - 1, term->cols - 1);
term,
&(struct coord){0, 0},
&(struct coord){term->cols - 1, term->rows - 1});
} }
else if (!enable && term->grid == &term->alt) { else if (!enable && term->grid == &term->alt) {
@ -885,27 +879,28 @@ csi_dispatch(struct terminal *term, uint8_t final)
int param = vt_param_get(term, 0, 0); int param = vt_param_get(term, 0, 0);
switch (param) { switch (param) {
case 0: case 0: {
/* From cursor to end of screen */ /* From cursor to end of screen */
const struct coord *cursor = &term->grid->cursor.point;
term_erase( term_erase(
term, term,
&term->grid->cursor.point, cursor->row, cursor->col,
&(struct coord){term->cols - 1, term->rows - 1}); term->rows - 1, term->cols - 1);
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
break; break;
}
case 1: case 1: {
/* From start of screen to cursor */ /* From start of screen to cursor */
term_erase(term, &(struct coord){0, 0}, &term->grid->cursor.point); const struct coord *cursor = &term->grid->cursor.point;
term_erase(term, 0, 0, cursor->row, cursor->col);
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
break; break;
}
case 2: case 2:
/* Erase entire screen */ /* Erase entire screen */
term_erase( term_erase(term, 0, 0, term->rows - 1, term->cols - 1);
term,
&(struct coord){0, 0},
&(struct coord){term->cols - 1, term->rows - 1});
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
break; break;
@ -927,30 +922,32 @@ csi_dispatch(struct terminal *term, uint8_t final)
int param = vt_param_get(term, 0, 0); int param = vt_param_get(term, 0, 0);
switch (param) { switch (param) {
case 0: case 0: {
/* From cursor to end of line */ /* From cursor to end of line */
const struct coord *cursor = &term->grid->cursor.point;
term_erase( term_erase(
term, term,
&term->grid->cursor.point, cursor->row, cursor->col,
&(struct coord){term->cols - 1, term->grid->cursor.point.row}); cursor->row, term->cols - 1);
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
break; break;
}
case 1: case 1: {
/* From start of line to cursor */ /* From start of line to cursor */
term_erase( const struct coord *cursor = &term->grid->cursor.point;
term, &(struct coord){0, term->grid->cursor.point.row}, &term->grid->cursor.point); term_erase(term, cursor->row, 0, cursor->row, cursor->col);
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
break; break;
}
case 2: case 2: {
/* Entire line */ /* Entire line */
term_erase( const struct coord *cursor = &term->grid->cursor.point;
term, term_erase(term, cursor->row, 0, cursor->row, term->cols - 1);
&(struct coord){0, term->grid->cursor.point.row},
&(struct coord){term->cols - 1, term->grid->cursor.point.row});
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
break; break;
}
default: default:
UNHANDLED(); UNHANDLED();
@ -1020,10 +1017,11 @@ csi_dispatch(struct terminal *term, uint8_t final)
term->grid->cur_row->dirty = true; term->grid->cur_row->dirty = true;
/* Erase the remainder of the line */ /* Erase the remainder of the line */
const struct coord *cursor = &term->grid->cursor.point;
term_erase( term_erase(
term, term,
&(struct coord){term->grid->cursor.point.col + remaining, term->grid->cursor.point.row}, cursor->row, cursor->col + remaining,
&(struct coord){term->cols - 1, term->grid->cursor.point.row}); cursor->row, term->cols - 1);
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
break; break;
} }
@ -1047,10 +1045,11 @@ csi_dispatch(struct terminal *term, uint8_t final)
term->grid->cur_row->dirty = true; term->grid->cur_row->dirty = true;
/* Erase (insert space characters) */ /* Erase (insert space characters) */
const struct coord *cursor = &term->grid->cursor.point;
term_erase( term_erase(
term, term,
&term->grid->cursor.point, cursor->row, cursor->col,
&(struct coord){term->grid->cursor.point.col + count - 1, term->grid->cursor.point.row}); cursor->row, cursor->col + count - 1);
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
break; break;
} }
@ -1074,10 +1073,11 @@ csi_dispatch(struct terminal *term, uint8_t final)
int count = min( int count = min(
vt_param_get(term, 0, 1), term->cols - term->grid->cursor.point.col); vt_param_get(term, 0, 1), term->cols - term->grid->cursor.point.col);
const struct coord *cursor = &term->grid->cursor.point;
term_erase( term_erase(
term, term,
&term->grid->cursor.point, cursor->row, cursor->col,
&(struct coord){term->grid->cursor.point.col + count - 1, term->grid->cursor.point.row}); cursor->row, cursor->col + count - 1);
term->grid->cursor.lcf = false; term->grid->cursor.lcf = false;
break; break;
} }

View file

@ -2108,31 +2108,32 @@ term_damage_scroll(struct terminal *term, enum damage_type damage_type,
} }
void void
term_erase(struct terminal *term, const struct coord *start, const struct coord *end) term_erase(struct terminal *term, int start_row, int start_col,
int end_row, int end_col)
{ {
xassert(start->row <= end->row); xassert(start_row <= end_row);
xassert(start->col <= end->col || start->row < end->row); xassert(start_col <= end_col || start_row < end_row);
if (start->row == end->row) { if (start_row == end_row) {
struct row *row = grid_row(term->grid, start->row); struct row *row = grid_row(term->grid, start_row);
erase_cell_range(term, row, start->col, end->col); erase_cell_range(term, row, start_col, end_col);
sixel_overwrite_by_row(term, start->row, start->col, end->col - start->col + 1); sixel_overwrite_by_row(term, start_row, start_col, end_col - start_col + 1);
return; return;
} }
xassert(end->row > start->row); xassert(end_row > start_row);
erase_cell_range( erase_cell_range(
term, grid_row(term->grid, start->row), start->col, term->cols - 1); term, grid_row(term->grid, start_row), start_col, term->cols - 1);
sixel_overwrite_by_row(term, start->row, start->col, term->cols - start->col); sixel_overwrite_by_row(term, start_row, start_col, term->cols - start_col);
for (int r = start->row + 1; r < end->row; r++) for (int r = start_row + 1; r < end_row; r++)
erase_line(term, grid_row(term->grid, r)); erase_line(term, grid_row(term->grid, r));
sixel_overwrite_by_rectangle( sixel_overwrite_by_rectangle(
term, start->row + 1, 0, end->row - start->row, term->cols); term, start_row + 1, 0, end_row - start_row, term->cols);
erase_cell_range(term, grid_row(term->grid, end->row), 0, end->col); erase_cell_range(term, grid_row(term->grid, end_row), 0, end_col);
sixel_overwrite_by_row(term, end->row, 0, end->col + 1); sixel_overwrite_by_row(term, end_row, 0, end_col + 1);
} }
void void

View file

@ -713,7 +713,9 @@ void term_damage_scroll(
struct scroll_region region, int lines); struct scroll_region region, int lines);
void term_erase( void term_erase(
struct terminal *term, const struct coord *start, const struct coord *end); struct terminal *term,
int start_row, int start_col,
int end_row, int end_col);
void term_erase_scrollback(struct terminal *term); void term_erase_scrollback(struct terminal *term);
int term_row_rel_to_abs(const struct terminal *term, int row); int term_row_rel_to_abs(const struct terminal *term, int row);