config: add [colors].dim0-7

This allows you to configure custom colors to be used when colors are
being dimmed (`\E[2m`).

It is implemented by color matching (just like
bold-text-in-bright=palette-based); the color-to-be-dimmed is matched
against the current color palette.

If it matches one of the regular colors (colors 0-7), the
corresponding “dim” color will be used.

If it matches one of the bright colors (colors 8-15), the
corresponding “regular” color will be used (but *only* if the “dim”
color has been set).

Otherwise, the color is dimmed by reducing its luminance.

The default behavior, i.e. when dim0-7 hasn’t been configured, is to
dim by reducing luminance for *all* colors. I.e. we don’t do any color
matching at all. In particular, this means that dimming a bright color
will *not* result in the corresponding “regular” color.

Closes #776
This commit is contained in:
Daniel Eklöf 2021-11-03 14:25:38 +01:00
parent 0d2a429109
commit c01904a2c7
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 91 additions and 9 deletions

View file

@ -244,7 +244,7 @@ color_hex_to_pixman(uint32_t color)
}
static inline uint32_t
color_dim(uint32_t color)
color_decrease_luminance(uint32_t color)
{
uint32_t alpha = color & 0xff000000;
int hue, sat, lum;
@ -252,6 +252,33 @@ color_dim(uint32_t color)
return alpha | hsl_to_rgb(hue, sat, lum / 1.5);
}
static inline uint32_t
color_dim(const struct terminal *term, uint32_t color)
{
const struct config *conf = term->conf;
const uint8_t custom_dim = conf->colors.use_custom.dim;
if (likely(custom_dim == 0))
return color_decrease_luminance(color);
for (size_t i = 0; i < 8; i++) {
if (((custom_dim >> i) & 1) == 0)
continue;
if (term->colors.table[0 + i] == color) {
/* “Regular” color, return the corresponding “dim” */
return conf->colors.dim[i];
}
else if (term->colors.table[8 + i] == color) {
/* “Bright” color, return the corresponding “regular” */
return term->colors.table[i];
}
}
return color_decrease_luminance(color);
}
static inline uint32_t
color_brighten(const struct terminal *term, uint32_t color)
{
@ -485,12 +512,12 @@ render_cell(struct terminal *term, pixman_image_t *pix,
}
if (cell->attrs.dim)
_fg = color_dim(_fg);
_fg = color_dim(term, _fg);
if (term->conf->bold_in_bright.enabled && cell->attrs.bold)
_fg = color_brighten(term, _fg);
if (cell->attrs.blink && term->blink.state == BLINK_OFF)
_fg = color_dim(_fg);
_fg = color_decrease_luminance(_fg);
pixman_color_t fg = color_hex_to_pixman(_fg);
pixman_color_t bg = color_hex_to_pixman_with_alpha(_bg, alpha);
@ -779,7 +806,7 @@ render_urgency(struct terminal *term, struct buffer *buf)
{
uint32_t red = term->colors.table[1];
if (term->is_searching)
red = color_dim(red);
red = color_decrease_luminance(red);
pixman_color_t bg = color_hex_to_pixman(red);
@ -1685,8 +1712,8 @@ render_csd_title(struct terminal *term, const struct csd_data *info,
: term->conf->colors.bg;
if (!term->visual_focus) {
bg = color_dim(bg);
fg = color_dim(fg);
bg = color_dim(term, bg);
fg = color_dim(term, fg);
}
const wchar_t *title_text = L"";
@ -2001,7 +2028,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx,
}
if (!term->visual_focus)
_color = color_dim(_color);
_color = color_dim(term, _color);
pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha);
render_csd_part(term, surf, buf, info->width, info->height, &color);