add custom highlight colors

This commit is contained in:
Piotr Kocia 2025-06-17 01:47:42 +02:00
parent 95090f0264
commit fa2b08846b
6 changed files with 28 additions and 28 deletions

View file

@ -1434,6 +1434,8 @@ parse_color_theme(struct context *ctx, struct color_theme *theme)
else if (streq(key, "background")) color = &theme->bg;
else if (streq(key, "selection-foreground")) color = &theme->selection_fg;
else if (streq(key, "selection-background")) color = &theme->selection_bg;
else if (streq(key, "highlight-foreground")) color = &theme->highlight_fg;
else if (streq(key, "highlight-background")) color = &theme->highlight_bg;
else if (streq(key, "jump-labels")) {
if (!value_to_two_colors(
@ -1505,20 +1507,6 @@ parse_color_theme(struct context *ctx, struct color_theme *theme)
return true;
}
else if (streq(key, "highlights")) {
if (!value_to_two_colors(
ctx,
&theme->highlights.fg,
&theme->highlights.bg,
false))
{
return false;
}
theme->use_custom.highlights = true;
return true;
}
else if (streq(key, "urls")) {
if (!value_to_color(ctx, &theme->url, false))
return false;

View file

@ -140,6 +140,8 @@ struct color_theme {
uint16_t alpha;
uint32_t selection_fg;
uint32_t selection_bg;
uint32_t highlight_fg;
uint32_t highlight_bg;
uint32_t url;
uint32_t dim[8];
@ -183,11 +185,6 @@ struct color_theme {
} match;
} search_box;
struct {
uint32_t fg;
uint32_t bg;
} highlights;
struct {
bool cursor:1;
bool jump_label:1;
@ -195,7 +192,6 @@ struct color_theme {
bool url:1;
bool search_box_no_match:1;
bool search_box_match:1;
bool highlights:1;
uint8_t dim;
} use_custom;
};

View file

@ -824,10 +824,24 @@ render_cell(struct terminal *term, pixman_image_t *pix,
const bool is_highlighted =
is_cell_highlighted(term, (struct coord){.row = row_no, .col = col});
if(is_highlighted) {
// TODO (kociap): Do the same thing as for selection colors.
if(term->conf->colors.use_custom.highlights) {
_fg = term->conf->colors.highlights.fg;
_bg = term->conf->colors.highlights.bg;
const uint32_t cell_fg = _fg;
const uint32_t cell_bg = _bg;
const uint32_t hl_fg = term->colors.highlight_fg;
const uint32_t hl_bg = term->colors.highlight_bg;
const bool custom_fg = hl_fg >> 24 == 0;
const bool custom_bg = hl_bg >> 24 == 0;
const bool custom_both = custom_fg && custom_bg;
if (custom_both) {
_fg = hl_fg;
_bg = hl_bg;
} else if (custom_bg) {
_bg = hl_bg;
_fg = cell->attrs.reverse ? cell_bg : cell_fg;
} else if (custom_fg) {
_fg = hl_fg;
_bg = cell->attrs.reverse ? cell_fg : cell_bg;
} else {
_fg = term->colors.table[0];
_bg = term->colors.table[1];

View file

@ -1323,6 +1323,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
.cursor_bg = (theme->use_custom.cursor ? 1u << 31 : 0) | theme->cursor.cursor,
.selection_fg = theme->selection_fg,
.selection_bg = theme->selection_bg,
.highlight_fg = theme->highlight_fg,
.highlight_bg = theme->highlight_bg,
.active_theme = conf->initial_color_theme,
},
.color_stack = {

View file

@ -409,6 +409,8 @@ struct colors {
uint32_t cursor_bg; /* cursor color */
uint32_t selection_fg;
uint32_t selection_bg;
uint32_t highlight_fg;
uint32_t highlight_bg;
enum which_color_theme active_theme;
};

View file

@ -731,6 +731,8 @@ test_section_colors(void)
test_color(&ctx, &parse_section_colors, "dim7", false, &conf.colors.dim[7]);
test_color(&ctx, &parse_section_colors, "selection-foreground", false, &conf.colors.selection_fg);
test_color(&ctx, &parse_section_colors, "selection-background", false, &conf.colors.selection_bg);
test_color(&ctx, &parse_section_colors, "highlight-foreground", false, &conf.colors.highlight_fg);
test_color(&ctx, &parse_section_colors, "highlight-background", false, &conf.colors.highlight_bg);
test_color(&ctx, &parse_section_colors, "urls", false, &conf.colors.url);
test_two_colors(&ctx, &parse_section_colors, "jump-labels", false,
&conf.colors.jump_label.fg,
@ -744,10 +746,6 @@ test_section_colors(void)
test_two_colors(&ctx, &parse_section_colors, "search-box-match", false,
&conf.colors.search_box.match.fg,
&conf.colors.search_box.match.bg);
test_two_colors(&ctx, &parse_section_colors, "highlights", false,
&conf.colors.highlights.fg,
&conf.colors.highlights.bg);
test_two_colors(&ctx, &parse_section_colors, "cursor", false,
&conf.colors.cursor.text,
&conf.colors.cursor.cursor);