aboutsummaryrefslogtreecommitdiff
path: root/osc.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-12-25 16:13:50 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-12-26 11:37:48 +0000
commitc2bf2d3650b6a837efec834d23b1c3774c263852 (patch)
treebb9bc7c3937fd12e7cdfe970b97bb50165b97a62 /osc.c
parentcsi: no need to set VT state’s fg/bg to the default ones on SGR reset (diff)
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.
Diffstat (limited to 'osc.c')
-rw-r--r--osc.c64
1 files changed, 4 insertions, 60 deletions
diff --git a/osc.c b/osc.c
index 357139b6..7144e111 100644
--- a/osc.c
+++ b/osc.c
@@ -527,61 +527,6 @@ osc_notify(struct terminal *term, char *string)
notify_notify(term, title, msg != NULL ? msg : "");
}
-static void
-update_color_in_grids(struct terminal *term, int palette_idx, uint32_t new_color)
-{
- /*
- * Update color of already rendered cells.
- *
- * Note that we do *not* store the original palette
- * index. Therefore, the best we can do is compare colors - if
- * they match, assume "our" palette index was the one used to
- * render the cell.
- *
- * There are a couple of cases where this isn't necessarily true:
- * - user has configured the 16 base colors with non-unique
- * colors. - the client has used 24-bit escapes for colors
- *
- * In general though, if the client configures the palette, it is
- * very likely only using index:ed coloring (i.e. not 24-bit
- * direct colors), and I hope that it is unusual with palettes
- * where all the colors aren't unique.
- *
- * TODO(?): for performance reasons, we only update the current
- * screen rows (of both grids). I.e. scrollback is *not* updated.
- */
- for (size_t i = 0; i < 2; i++) {
- struct grid *grid = i == 0 ? &term->normal : &term->alt;
-
- for (size_t r = 0; r < term->rows; r++) {
- struct row *row = grid_row(grid, r);
- xassert(row != NULL);
-
- for (size_t c = 0; c < term->grid->num_cols; c++) {
- struct cell *cell = &row->cells[c];
- enum color_source fg_src = cell->attrs.fg_src;
- enum color_source bg_src = cell->attrs.bg_src;
-
- if ((fg_src == COLOR_BASE16 || fg_src == COLOR_BASE256) &&
- cell->attrs.fg == term->colors.table[palette_idx])
- {
- cell->attrs.fg = new_color;
- cell->attrs.clean = 0;
- row->dirty = true;
- }
-
- if ((bg_src == COLOR_BASE16 || bg_src == COLOR_BASE256) &&
- cell->attrs.bg == term->colors.table[palette_idx])
- {
- cell->attrs.bg = new_color;
- cell->attrs.clean = 0;
- row->dirty = true;
- }
- }
- }
- }
-}
-
void
osc_dispatch(struct terminal *term)
{
@@ -668,8 +613,8 @@ osc_dispatch(struct terminal *term)
LOG_DBG("change color definition for #%u from %06x to %06x",
idx, term->colors.table[idx], color);
- update_color_in_grids(term, idx, color);
term->colors.table[idx] = color;
+ term_damage_view(term);
}
}
@@ -811,11 +756,9 @@ osc_dispatch(struct terminal *term)
if (strlen(string) == 0) {
LOG_DBG("resetting all colors");
- for (size_t i = 0; i < ALEN(term->colors.table); i++) {
- update_color_in_grids(term, i, term->conf->colors.table[i]);
+ for (size_t i = 0; i < ALEN(term->colors.table); i++)
term->colors.table[i] = term->conf->colors.table[i];
}
- }
else {
for (const char *s_idx = strtok(string, ";");
@@ -835,11 +778,12 @@ osc_dispatch(struct terminal *term)
}
LOG_DBG("resetting color #%u", idx);
- update_color_in_grids(term, idx, term->conf->colors.table[idx]);
term->colors.table[idx] = term->conf->colors.table[idx];
}
+
}
+ term_damage_view(term);
break;
}