Add nicer dark and light colour sets (themes) used on terminals with 256

or more colours. Currently based these on emacs but they could change.
Terminals with fewer colours use the ANSI colours. A new "theme" option
overrides the detected theme (set to "terminal" to go back to ANSI
colours).
This commit is contained in:
nicm
2026-06-25 23:17:25 +00:00
parent 2d0845860a
commit 8c55a388cd
8 changed files with 478 additions and 29 deletions

29
tty.c
View File

@@ -51,6 +51,7 @@ static void tty_check_bg(struct tty *, struct colour_palette *,
struct grid_cell *);
static void tty_check_us(struct tty *, struct colour_palette *,
struct grid_cell *);
static int tty_map_theme_colour(struct tty *, int);
static void tty_colours_fg(struct tty *, const struct grid_cell *);
static void tty_colours_bg(struct tty *, const struct grid_cell *);
static void tty_colours_us(struct tty *, const struct grid_cell *);
@@ -2517,6 +2518,9 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc,
gc2.bg = changed;
}
}
gc2.fg = tty_map_theme_colour(tty, gc2.fg);
gc2.bg = tty_map_theme_colour(tty, gc2.bg);
gc2.us = tty_map_theme_colour(tty, gc2.us);
if (style_ctx->dim != 0) {
gc2.fg = tty_dim_default_colour(tty, gc2.fg, 1);
gc2.bg = tty_dim_default_colour(tty, gc2.bg, 0);
@@ -2666,6 +2670,28 @@ tty_colours(struct tty *tty, const struct grid_cell *gc)
tty_colours_us(tty, gc);
}
static int
tty_map_theme_colour(struct tty *tty, int colour)
{
struct client *c;
u_int n;
int m;
if (~colour & COLOUR_FLAG_THEME)
return (colour);
n = colour & 0xff;
if (n >= COLOUR_THEME_COUNT)
return (8);
if (tty == NULL || (c = tty->client) == NULL)
return (8);
m = c->theme_colours[n];
if (m == -1 || (m & COLOUR_FLAG_THEME))
return (8);
return (m);
}
static void
tty_check_fg(struct tty *tty, struct colour_palette *palette,
struct grid_cell *gc)
@@ -2688,6 +2714,7 @@ tty_check_fg(struct tty *tty, struct colour_palette *palette,
if ((c = colour_palette_get(palette, c)) != -1)
gc->fg = c;
}
gc->fg = tty_map_theme_colour(tty, gc->fg);
/* Is this a 24-bit colour? */
if (gc->fg & COLOUR_FLAG_RGB) {
@@ -2748,6 +2775,7 @@ tty_check_bg(struct tty *tty, struct colour_palette *palette,
if ((c = colour_palette_get(palette, gc->bg)) != -1)
gc->bg = c;
}
gc->bg = tty_map_theme_colour(tty, gc->bg);
/* Is this a 24-bit colour? */
if (gc->bg & COLOUR_FLAG_RGB) {
@@ -2798,6 +2826,7 @@ tty_check_us(__unused struct tty *tty, struct colour_palette *palette,
if ((c = colour_palette_get(palette, gc->us)) != -1)
gc->us = c;
}
gc->us = tty_map_theme_colour(tty, gc->us);
/* Convert underscore colour if only RGB can be supported. */
if (!tty_term_has(tty->term, TTYC_SETULC1)) {