csi: store color index, not actual color, in cell’s fg/bg attributes

When using indexed colors (i.e. SGR 30/40/90/100), store the index
into the cell’s fg/bg attributes, not the actual color value.

This has a couple of consequences:

Color table lookup is now done when rendering. This means a rendered
cell will always reflect the *current* color table, not the color
table that was in use when the cell was printed to.

This simplifies the OSC-4/104 logic, since we no longer need to update
the grid - we just have to damage it to trigger rendering.

Furthermore, this change simplifies the VT parsing, since we no longer
need to do any memory loads (except loading the SGR parameter values),
only writes.
This commit is contained in:
Daniel Eklöf 2021-12-25 17:13:50 +01:00
parent 8bf757f466
commit c2bf2d3650
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 43 additions and 74 deletions

20
csi.c
View file

@ -114,7 +114,7 @@ csi_sgr(struct terminal *term)
case 36:
case 37:
term->vt.attrs.fg_src = COLOR_BASE16;
term->vt.attrs.fg = term->colors.table[param - 30];
term->vt.attrs.fg = param - 30;
break;
case 38: {
@ -122,9 +122,8 @@ csi_sgr(struct terminal *term)
if (term->vt.params.idx - i - 1 >= 2 &&
term->vt.params.v[i + 1].value == 5)
{
uint8_t idx = term->vt.params.v[i + 2].value;
term->vt.attrs.fg_src = COLOR_BASE256;
term->vt.attrs.fg = term->colors.table[idx];
term->vt.attrs.fg = term->vt.params.v[i + 2].value;
i += 2;
}
@ -147,9 +146,8 @@ csi_sgr(struct terminal *term)
{
const struct vt_param *param = &term->vt.params.v[i];
uint8_t idx = param->sub.value[1];
term->vt.attrs.fg_src = COLOR_BASE256;
term->vt.attrs.fg = term->colors.table[idx];
term->vt.attrs.fg = param->sub.value[1];
}
/*
@ -207,7 +205,7 @@ csi_sgr(struct terminal *term)
case 46:
case 47:
term->vt.attrs.bg_src = COLOR_BASE16;
term->vt.attrs.bg = term->colors.table[param - 40];
term->vt.attrs.bg = param - 40;
break;
case 48: {
@ -215,9 +213,8 @@ csi_sgr(struct terminal *term)
if (term->vt.params.idx - i - 1 >= 2 &&
term->vt.params.v[i + 1].value == 5)
{
uint8_t idx = term->vt.params.v[i + 2].value;
term->vt.attrs.bg_src = COLOR_BASE256;
term->vt.attrs.bg = term->colors.table[idx];
term->vt.attrs.bg = term->vt.params.v[i + 2].value;
i += 2;
}
@ -240,9 +237,8 @@ csi_sgr(struct terminal *term)
{
const struct vt_param *param = &term->vt.params.v[i];
uint8_t idx = param->sub.value[1];
term->vt.attrs.bg_src = COLOR_BASE256;
term->vt.attrs.bg = term->colors.table[idx];
term->vt.attrs.bg = param->sub.value[1];
}
/*
@ -298,7 +294,7 @@ csi_sgr(struct terminal *term)
case 96:
case 97:
term->vt.attrs.fg_src = COLOR_BASE16;
term->vt.attrs.fg = term->colors.table[param - 90 + 8];
term->vt.attrs.fg = param - 90 + 8;
break;
/* Bright background colors */
@ -311,7 +307,7 @@ csi_sgr(struct terminal *term)
case 106:
case 107:
term->vt.attrs.bg_src = COLOR_BASE16;
term->vt.attrs.bg = term->colors.table[param - 100 + 8];
term->vt.attrs.bg = param - 100 + 8;
break;
default: