Add options for custom background colors

This commit is contained in:
Lars Christensen 2025-07-30 12:35:51 +02:00
parent 83303bd2a4
commit 64682f642d
5 changed files with 33 additions and 1 deletions

View file

@ -1388,6 +1388,15 @@ parse_color_theme(struct context *ctx, struct color_theme *theme)
return true; return true;
} }
else if (key_len == 11 && str_has_prefix(key, "background") && last_digit < 8)
{
if (!value_to_color(ctx, &theme->background[last_digit], false))
return false;
theme->use_custom.background |= 1 << last_digit;
return true;
}
else if (str_has_prefix(key, "sixel") && else if (str_has_prefix(key, "sixel") &&
((key_len == 6 && last_digit < 10) || ((key_len == 6 && last_digit < 10) ||
(key_len == 7 && key[5] == '1' && last_digit < 6))) (key_len == 7 && key[5] == '1' && last_digit < 6)))

View file

@ -143,6 +143,7 @@ struct color_theme {
uint32_t url; uint32_t url;
uint32_t dim[8]; uint32_t dim[8];
uint32_t background[8];
uint32_t sixel[16]; uint32_t sixel[16];
enum { enum {
@ -186,6 +187,7 @@ struct color_theme {
bool search_box_no_match:1; bool search_box_no_match:1;
bool search_box_match:1; bool search_box_match:1;
uint8_t dim; uint8_t dim;
uint8_t background;
} use_custom; } use_custom;
}; };

View file

@ -1017,6 +1017,14 @@ dark theme (since the default theme is dark).
_e9e836_, _5dc5f8_, _feabf2_, _24dfc4_, _ffffff_ (starlight _e9e836_, _5dc5f8_, _feabf2_, _24dfc4_, _ffffff_ (starlight
theme, V4). theme, V4).
*background0*, *background1* *..* *background7*
Custom colors to use for background colors. By default the eight
foreground colors are used.
Note that applications can change the *regularN* colors at runtime
which affects the background colors when *backgroundN* is not
defined.
*dim0*, *dim1* *..* *dim7* *dim0*, *dim1* *..* *dim7*
Custom colors to use with dimmed colors. Dimmed colors do not have Custom colors to use with dimmed colors. Dimmed colors do not have
an entry in the color palette. Applications emit them by combining an entry in the color palette. Applications emit them by combining

View file

@ -134,6 +134,16 @@
# ... # ...
# dim7=<not-set> # dim7=<not-set>
## custom background colors (see foot.ini(5) man page)
# background0=<not set> # black
# background1=<not set> # red
# background2=<not set> # green
# background3=<not set> # yellow
# background4=<not set> # blue
# background5=<not set> # magenta
# background6=<not set> # cyan
# background7=<not set> # white
## The remaining 256-color palette ## The remaining 256-color palette
# 16 = <256-color palette #16> # 16 = <256-color palette #16>
# ... # ...

View file

@ -725,7 +725,10 @@ render_cell(struct terminal *term, pixman_image_t *pix,
case COLOR_BASE16: case COLOR_BASE16:
case COLOR_BASE256: case COLOR_BASE256:
xassert(cell->attrs.bg < ALEN(term->colors.table)); xassert(cell->attrs.bg < ALEN(term->colors.table));
_bg = term->colors.table[cell->attrs.bg]; if (cell->attrs.bg < 8 && term->conf->colors.use_custom.background & (1 << cell->attrs.bg))
_bg = term->conf->colors.background[cell->attrs.bg];
else
_bg = term->colors.table[cell->attrs.bg];
break; break;
case COLOR_DEFAULT: case COLOR_DEFAULT: