render: add a 'clean' bit to each cell; only render cells that aren't clean

This patch takes a bit from the foreground color value in a
cell (todo: split up foreground/background into bitfields with a
separate field for 'foreground/background' has been set), and only
re-renders cells that aren't marked as clean.

Note: we use a 'clean' bit rather than a 'dirty' bit to make it easy
to erase cells - we can (keep doing) do that by simply memsetting a
cell range to 0.
This commit is contained in:
Daniel Eklöf 2019-07-30 18:03:03 +02:00
parent c531795b83
commit 85ef9df586
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 52 additions and 33 deletions

25
csi.c
View file

@ -126,7 +126,7 @@ csi_sgr(struct terminal *term)
case 35:
case 36:
case 37:
term->vt.attrs.foreground = 1 << 31 | term->colors.regular[param - 30];
term->vt.attrs.foreground = 1 << 30 | term->colors.regular[param - 30];
break;
case 38: {
@ -141,7 +141,7 @@ csi_sgr(struct terminal *term)
color = term->colors.bright[idx - 8];
else
color = colors256[idx];
term->vt.attrs.foreground = 1 << 31 | color;
term->vt.attrs.foreground = 1 << 30 | color;
i += 2;
}
@ -152,7 +152,7 @@ csi_sgr(struct terminal *term)
uint8_t r = term->vt.params.v[i + 2].value;
uint8_t g = term->vt.params.v[i + 3].value;
uint8_t b = term->vt.params.v[i + 4].value;
term->vt.attrs.foreground = 1 << 31 | r << 16 | g << 8 | b;
term->vt.attrs.foreground = 1 << 30 | r << 16 | g << 8 | b;
i += 4;
}
@ -168,7 +168,7 @@ csi_sgr(struct terminal *term)
/* 6 - CS tolerance */
/* 7 - color space associated with tolerance */
term->vt.attrs.foreground = 1 << 31 | r << 16 | g << 8 | b;
term->vt.attrs.foreground = 1 << 30 | r << 16 | g << 8 | b;
} else {
LOG_ERR("invalid CSI SGR sequence");
abort();
@ -195,7 +195,7 @@ csi_sgr(struct terminal *term)
case 45:
case 46:
case 47:
term->vt.attrs.background = 1 << 31 | term->colors.regular[param - 40];
term->vt.attrs.background = 1 << 30 | term->colors.regular[param - 40];
break;
case 48: {
@ -211,7 +211,7 @@ csi_sgr(struct terminal *term)
color = term->colors.bright[idx - 8];
else
color = colors256[idx];
term->vt.attrs.background = 1 << 31 | color;
term->vt.attrs.background = 1 << 30 | color;
i += 2;
}
@ -221,7 +221,7 @@ csi_sgr(struct terminal *term)
uint8_t r = term->vt.params.v[i + 2].value;
uint8_t g = term->vt.params.v[i + 3].value;
uint8_t b = term->vt.params.v[i + 4].value;
term->vt.attrs.background = 1 << 31 | r << 16 | g << 8 | b;
term->vt.attrs.background = 1 << 30 | r << 16 | g << 8 | b;
i += 4;
}
@ -238,7 +238,7 @@ csi_sgr(struct terminal *term)
/* 6 - CS tolerance */
/* 7 - color space associated with tolerance */
term->vt.attrs.background = 1 << 31 | r << 16 | g << 8 | b;
term->vt.attrs.background = 1 << 30 | r << 16 | g << 8 | b;
} else {
LOG_ERR("invalid CSI SGR sequence");
abort();
@ -265,7 +265,7 @@ csi_sgr(struct terminal *term)
case 95:
case 96:
case 97:
term->vt.attrs.foreground = 1 << 31 | term->colors.bright[param - 90];
term->vt.attrs.foreground = 1 << 30 | term->colors.bright[param - 90];
break;
/* Regular background colors */
@ -277,7 +277,7 @@ csi_sgr(struct terminal *term)
case 105:
case 106:
case 107:
term->vt.attrs.background = 1 << 31 | term->colors.bright[param - 100];
term->vt.attrs.background = 1 << 30 | term->colors.bright[param - 100];
break;
default:
@ -487,6 +487,9 @@ csi_dispatch(struct terminal *term, uint8_t final)
memmove(&term->grid->cur_row->cells[term->cursor.col],
&term->grid->cur_row->cells[term->cursor.col + count],
remaining * sizeof(term->grid->cur_row->cells[0]));
for (size_t c = 0; c < remaining; c++)
term->grid->cur_row->cells[term->cursor.col + c].attrs.clean = 0;
term->grid->cur_row->dirty = true;
/* Erase the remainder of the line */
@ -511,6 +514,8 @@ csi_dispatch(struct terminal *term, uint8_t final)
memmove(&term->grid->cur_row->cells[term->cursor.col + count],
&term->grid->cur_row->cells[term->cursor.col],
remaining * sizeof(term->grid->cur_row->cells[0]));
for (size_t c = 0; c < remaining; c++)
term->grid->cur_row->cells[term->cursor.col + count + c].attrs.clean = 0;
term->grid->cur_row->dirty = true;
/* Erase (insert space characters) */