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:
nicm
2021-08-11 20:49:55 +00:00
parent 01fd4b997e
commit 7eea3d7ab8
12 changed files with 352 additions and 239 deletions

View File

@ -478,6 +478,14 @@ window_set_active_pane(struct window *w, struct window_pane *wp, int notify)
return (1);
}
static int
window_pane_get_palette(struct window_pane *wp, int c)
{
if (wp == NULL)
return (-1);
return (colour_palette_get(&wp->palette, c));
}
void
window_redraw_active_switch(struct window *w, struct window_pane *wp)
{
@ -855,9 +863,6 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->fd = -1;
wp->fg = 8;
wp->bg = 8;
TAILQ_INIT(&wp->modes);
TAILQ_INIT (&wp->resize_queue);
@ -867,6 +872,7 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->pipe_fd = -1;
colour_palette_init(&wp->palette);
screen_init(&wp->base, sx, sy, hlimit);
wp->screen = &wp->base;
@ -916,7 +922,7 @@ window_pane_destroy(struct window_pane *wp)
free((void *)wp->cwd);
free(wp->shell);
cmd_free_argv(wp->argc, wp->argv);
free(wp->palette);
colour_palette_free(&wp->palette);
free(wp);
}
@ -968,7 +974,7 @@ window_pane_set_event(struct window_pane *wp)
wp->event = bufferevent_new(wp->fd, window_pane_read_callback,
NULL, window_pane_error_callback, wp);
wp->ictx = input_init(wp, wp->event);
wp->ictx = input_init(wp, wp->event, &wp->palette);
bufferevent_enable(wp->event, EV_READ|EV_WRITE);
}
@ -1000,60 +1006,6 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy)
wme->mode->resize(wme, sx, sy);
}
void
window_pane_set_palette(struct window_pane *wp, u_int n, int colour)
{
if (n > 0xff)
return;
if (wp->palette == NULL)
wp->palette = xcalloc(0x100, sizeof *wp->palette);
wp->palette[n] = colour;
wp->flags |= PANE_REDRAW;
}
void
window_pane_unset_palette(struct window_pane *wp, u_int n)
{
if (n > 0xff || wp->palette == NULL)
return;
wp->palette[n] = 0;
wp->flags |= PANE_REDRAW;
}
void
window_pane_reset_palette(struct window_pane *wp)
{
if (wp->palette == NULL)
return;
free(wp->palette);
wp->palette = NULL;
wp->flags |= PANE_REDRAW;
}
int
window_pane_get_palette(struct window_pane *wp, int c)
{
int new;
if (wp == NULL || wp->palette == NULL)
return (-1);
new = -1;
if (c < 8)
new = wp->palette[c];
else if (c >= 90 && c <= 97)
new = wp->palette[8 + c - 90];
else if (c & COLOUR_FLAG_256)
new = wp->palette[c & ~COLOUR_FLAG_256];
if (new == 0)
return (-1);
return (new);
}
int
window_pane_set_mode(struct window_pane *wp, struct window_pane *swp,
const struct window_mode *mode, struct cmd_find_state *fs,