diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-08-11 20:49:56 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-08-11 20:49:56 +0000 |
commit | a09f81c7ed125be3fd3535c31155c550973b3e55 (patch) | |
tree | 08cd9917d90f19f678922f3d0aa868a9b55389cf /usr.bin/tmux/window.c | |
parent | 9dae6e90952aaca8ad34c186222d2ee05c4343e5 (diff) |
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.
Diffstat (limited to 'usr.bin/tmux/window.c')
-rw-r--r-- | usr.bin/tmux/window.c | 72 |
1 files changed, 12 insertions, 60 deletions
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index c267b4395e3..fbf3da32fbe 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.272 2021/06/10 07:33:41 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.273 2021/08/11 20:49:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -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, |