From c2bf2d3650b6a837efec834d23b1c3774c263852 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 25 Dec 2021 17:13:50 +0100 Subject: csi: store color index, not actual color, in cell’s fg/bg attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- csi.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'csi.c') diff --git a/csi.c b/csi.c index cee133e9..858befba 100644 --- a/csi.c +++ b/csi.c @@ -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: -- cgit v1.3