mirror of
https://github.com/tmux/tmux.git
synced 2025-09-01 20:57:00 +00:00
Break the colour palette into a struct rather than just a single array
and use that to support the OSC palette-setting sequences in popups. Also add a pane-colours array option to specify the defaults. GitHub issue 2815.
This commit is contained in:
74
tty.c
74
tty.c
@ -45,9 +45,12 @@ static void tty_cursor_pane_unless_wrap(struct tty *,
|
||||
const struct tty_ctx *, u_int, u_int);
|
||||
static void tty_invalidate(struct tty *);
|
||||
static void tty_colours(struct tty *, const struct grid_cell *);
|
||||
static void tty_check_fg(struct tty *, int *, struct grid_cell *);
|
||||
static void tty_check_bg(struct tty *, int *, struct grid_cell *);
|
||||
static void tty_check_us(struct tty *, int *, struct grid_cell *);
|
||||
static void tty_check_fg(struct tty *, struct colour_palette *,
|
||||
struct grid_cell *);
|
||||
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 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 *);
|
||||
@ -66,7 +69,7 @@ static void tty_emulate_repeat(struct tty *, enum tty_code_code,
|
||||
static void tty_repeat_space(struct tty *, u_int);
|
||||
static void tty_draw_pane(struct tty *, const struct tty_ctx *, u_int);
|
||||
static void tty_default_attributes(struct tty *, const struct grid_cell *,
|
||||
int *, u_int);
|
||||
struct colour_palette *, u_int);
|
||||
static int tty_check_overlay(struct tty *, u_int, u_int);
|
||||
|
||||
#define tty_use_margin(tty) \
|
||||
@ -939,27 +942,6 @@ tty_update_client_offset(struct client *c)
|
||||
c->flags |= (CLIENT_REDRAWWINDOW|CLIENT_REDRAWSTATUS);
|
||||
}
|
||||
|
||||
/* Get a palette entry. */
|
||||
static int
|
||||
tty_get_palette(int *palette, int c)
|
||||
{
|
||||
int new;
|
||||
|
||||
if (palette == NULL)
|
||||
return (-1);
|
||||
|
||||
new = -1;
|
||||
if (c < 8)
|
||||
new = palette[c];
|
||||
else if (c >= 90 && c <= 97)
|
||||
new = palette[8 + c - 90];
|
||||
else if (c & COLOUR_FLAG_256)
|
||||
new = palette[c & ~COLOUR_FLAG_256];
|
||||
if (new == 0)
|
||||
return (-1);
|
||||
return (new);
|
||||
}
|
||||
|
||||
/*
|
||||
* Is the region large enough to be worth redrawing once later rather than
|
||||
* probably several times now? Currently yes if it is more than 50% of the
|
||||
@ -1341,7 +1323,8 @@ tty_check_overlay(struct tty *tty, u_int px, u_int py)
|
||||
|
||||
void
|
||||
tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
|
||||
u_int atx, u_int aty, const struct grid_cell *defaults, int *palette)
|
||||
u_int atx, u_int aty, const struct grid_cell *defaults,
|
||||
struct colour_palette *palette)
|
||||
{
|
||||
struct grid *gd = s->grid;
|
||||
struct grid_cell gc, last;
|
||||
@ -1356,6 +1339,8 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
|
||||
|
||||
log_debug("%s: px=%u py=%u nx=%u atx=%u aty=%u", __func__,
|
||||
px, py, nx, atx, aty);
|
||||
log_debug("%s: defaults: fg=%d, bg=%d", __func__, defaults->fg,
|
||||
defaults->bg);
|
||||
|
||||
/*
|
||||
* py is the line in the screen to draw.
|
||||
@ -2061,7 +2046,7 @@ tty_cmd_syncstart(struct tty *tty, __unused const struct tty_ctx *ctx)
|
||||
|
||||
void
|
||||
tty_cell(struct tty *tty, const struct grid_cell *gc,
|
||||
const struct grid_cell *defaults, int *palette)
|
||||
const struct grid_cell *defaults, struct colour_palette *palette)
|
||||
{
|
||||
const struct grid_cell *gcp;
|
||||
|
||||
@ -2381,17 +2366,19 @@ out:
|
||||
|
||||
void
|
||||
tty_attributes(struct tty *tty, const struct grid_cell *gc,
|
||||
const struct grid_cell *defaults, int *palette)
|
||||
const struct grid_cell *defaults, struct colour_palette *palette)
|
||||
{
|
||||
struct grid_cell *tc = &tty->cell, gc2;
|
||||
int changed;
|
||||
|
||||
/* Copy cell and update default colours. */
|
||||
memcpy(&gc2, gc, sizeof gc2);
|
||||
if (gc2.fg == 8)
|
||||
gc2.fg = defaults->fg;
|
||||
if (gc2.bg == 8)
|
||||
gc2.bg = defaults->bg;
|
||||
if (~gc->flags & GRID_FLAG_NOPALETTE) {
|
||||
if (gc2.fg == 8)
|
||||
gc2.fg = defaults->fg;
|
||||
if (gc2.bg == 8)
|
||||
gc2.bg = defaults->bg;
|
||||
}
|
||||
|
||||
/* Ignore cell if it is the same as the last one. */
|
||||
if (gc2.attr == tty->last_cell.attr &&
|
||||
@ -2533,13 +2520,14 @@ tty_colours(struct tty *tty, const struct grid_cell *gc)
|
||||
if (!COLOUR_DEFAULT(gc->bg) && gc->bg != tc->bg)
|
||||
tty_colours_bg(tty, gc);
|
||||
|
||||
/* Set the underscore color. */
|
||||
/* Set the underscore colour. */
|
||||
if (gc->us != tc->us)
|
||||
tty_colours_us(tty, gc);
|
||||
}
|
||||
|
||||
static void
|
||||
tty_check_fg(struct tty *tty, int *palette, struct grid_cell *gc)
|
||||
tty_check_fg(struct tty *tty, struct colour_palette *palette,
|
||||
struct grid_cell *gc)
|
||||
{
|
||||
u_char r, g, b;
|
||||
u_int colours;
|
||||
@ -2554,7 +2542,7 @@ tty_check_fg(struct tty *tty, int *palette, struct grid_cell *gc)
|
||||
c = gc->fg;
|
||||
if (c < 8 && gc->attr & GRID_ATTR_BRIGHT)
|
||||
c += 90;
|
||||
if ((c = tty_get_palette(palette, c)) != -1)
|
||||
if ((c = colour_palette_get(palette, c)) != -1)
|
||||
gc->fg = c;
|
||||
}
|
||||
|
||||
@ -2595,7 +2583,8 @@ tty_check_fg(struct tty *tty, int *palette, struct grid_cell *gc)
|
||||
}
|
||||
|
||||
static void
|
||||
tty_check_bg(struct tty *tty, int *palette, struct grid_cell *gc)
|
||||
tty_check_bg(struct tty *tty, struct colour_palette *palette,
|
||||
struct grid_cell *gc)
|
||||
{
|
||||
u_char r, g, b;
|
||||
u_int colours;
|
||||
@ -2603,7 +2592,7 @@ tty_check_bg(struct tty *tty, int *palette, struct grid_cell *gc)
|
||||
|
||||
/* Perform substitution if this pane has a palette. */
|
||||
if (~gc->flags & GRID_FLAG_NOPALETTE) {
|
||||
if ((c = tty_get_palette(palette, gc->bg)) != -1)
|
||||
if ((c = colour_palette_get(palette, gc->bg)) != -1)
|
||||
gc->bg = c;
|
||||
}
|
||||
|
||||
@ -2646,13 +2635,14 @@ tty_check_bg(struct tty *tty, int *palette, struct grid_cell *gc)
|
||||
}
|
||||
|
||||
static void
|
||||
tty_check_us(__unused struct tty *tty, int *palette, struct grid_cell *gc)
|
||||
tty_check_us(__unused struct tty *tty, struct colour_palette *palette,
|
||||
struct grid_cell *gc)
|
||||
{
|
||||
int c;
|
||||
|
||||
/* Perform substitution if this pane has a palette. */
|
||||
if (~gc->flags & GRID_FLAG_NOPALETTE) {
|
||||
if ((c = tty_get_palette(palette, gc->us)) != -1)
|
||||
if ((c = colour_palette_get(palette, gc->us)) != -1)
|
||||
gc->us = c;
|
||||
}
|
||||
|
||||
@ -2793,8 +2783,8 @@ static void
|
||||
tty_window_default_style(struct grid_cell *gc, struct window_pane *wp)
|
||||
{
|
||||
memcpy(gc, &grid_default_cell, sizeof *gc);
|
||||
gc->fg = wp->fg;
|
||||
gc->bg = wp->bg;
|
||||
gc->fg = wp->palette.fg;
|
||||
gc->bg = wp->palette.bg;
|
||||
}
|
||||
|
||||
void
|
||||
@ -2831,7 +2821,7 @@ tty_default_colours(struct grid_cell *gc, struct window_pane *wp)
|
||||
|
||||
static void
|
||||
tty_default_attributes(struct tty *tty, const struct grid_cell *defaults,
|
||||
int *palette, u_int bg)
|
||||
struct colour_palette *palette, u_int bg)
|
||||
{
|
||||
struct grid_cell gc;
|
||||
|
||||
|
Reference in New Issue
Block a user