From ffda99cd39c9191a7a3102bcfe997908a2fd251d Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 25 Oct 2021 09:38:36 +0000 Subject: [PATCH] Add -s and -S to display-popup to set popup and border style, from Alexis Hildebrandt in GitHub issue 2931. --- usr.bin/tmux/cmd-display-menu.c | 13 ++++++++----- usr.bin/tmux/popup.c | 26 +++++++++++++++++++++----- usr.bin/tmux/screen-write.c | 6 +++--- usr.bin/tmux/tmux.1 | 16 ++++++++++++++-- usr.bin/tmux/tmux.h | 5 +++-- 5 files changed, 49 insertions(+), 17 deletions(-) diff --git a/usr.bin/tmux/cmd-display-menu.c b/usr.bin/tmux/cmd-display-menu.c index 5648256f5d7..7df92972fb9 100644 --- a/usr.bin/tmux/cmd-display-menu.c +++ b/usr.bin/tmux/cmd-display-menu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-display-menu.c,v 1.36 2021/10/20 09:50:40 nicm Exp $ */ +/* $OpenBSD: cmd-display-menu.c,v 1.37 2021/10/25 09:38:36 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott @@ -53,11 +53,12 @@ const struct cmd_entry cmd_display_popup_entry = { .name = "display-popup", .alias = "popup", - .args = { "Bb:Cc:d:e:Eh:t:T:w:x:y:", 0, -1, NULL }, + .args = { "Bb:Cc:d:e:Eh:s:S:t:T:w:x:y:", 0, -1, NULL }, .usage = "[-BCE] [-b border-lines] [-c target-client] " "[-d start-directory] [-e environment] [-h height] " - CMD_TARGET_PANE_USAGE " [-T title] " - "[-w width] [-x position] [-y position] [shell-command]", + "[-s style] [-S border-style] " CMD_TARGET_PANE_USAGE + "[-T title] [-w width] [-x position] [-y position] " + "[shell-command]", .target = { 't', CMD_FIND_PANE, 0 }, @@ -355,6 +356,8 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) struct client *tc = cmdq_get_target_client(item); struct tty *tty = &tc->tty; const char *value, *shell, *shellcmd = NULL; + const char *style = args_get(args, 's'); + const char *border_style = args_get(args, 'S'); char *cwd, *cause = NULL, **argv = NULL, *title; int flags = 0, argc = 0; enum box_lines lines = BOX_LINES_DEFAULT; @@ -448,7 +451,7 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) else if (args_has(args, 'E')) flags |= POPUP_CLOSEEXIT; if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc, - argv, cwd, title, tc, s, NULL, NULL) != 0) { + argv, cwd, title, tc, s, style, border_style, NULL, NULL) != 0) { cmd_free_argv(argc, argv); if (env != NULL) environ_free(env); diff --git a/usr.bin/tmux/popup.c b/usr.bin/tmux/popup.c index 865c82944c2..f1e6cba5fdf 100644 --- a/usr.bin/tmux/popup.c +++ b/usr.bin/tmux/popup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: popup.c,v 1.41 2021/10/25 09:22:17 nicm Exp $ */ +/* $OpenBSD: popup.c,v 1.42 2021/10/25 09:38:36 nicm Exp $ */ /* * Copyright (c) 2020 Nicholas Marriott @@ -237,9 +237,9 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx) screen_write_stop(&ctx); memcpy(&defaults, &pd->defaults, sizeof defaults); - if (COLOUR_DEFAULT(defaults.fg)) + if (defaults.fg == 8) defaults.fg = palette->fg; - if (COLOUR_DEFAULT(defaults.bg)) + if (defaults.bg == 8) defaults.bg = palette->bg; if (pd->md != NULL) { @@ -636,11 +636,13 @@ int popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, u_int py, u_int sx, u_int sy, struct environ *env, const char *shellcmd, int argc, char **argv, const char *cwd, const char *title, struct client *c, - struct session *s, popup_close_cb cb, void *arg) + struct session *s, const char* style, const char* border_style, + popup_close_cb cb, void *arg) { struct popup_data *pd; u_int jx, jy; struct options *o; + struct style sytmp; if (s != NULL) o = s->curw->window->options; @@ -678,6 +680,13 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, pd->border_lines = lines; memcpy(&pd->border_cell, &grid_default_cell, sizeof pd->border_cell); style_apply(&pd->border_cell, o, "popup-border-style", NULL); + if (border_style != NULL) { + style_set(&sytmp, &grid_default_cell); + if (style_parse(&sytmp, &pd->border_cell, border_style) == 0) { + pd->border_cell.fg = sytmp.gc.fg; + pd->border_cell.bg = sytmp.gc.bg; + } + } pd->border_cell.attr = 0; screen_init(&pd->s, sx - 2, sy - 2, 0); @@ -686,6 +695,13 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, memcpy(&pd->defaults, &grid_default_cell, sizeof pd->defaults); style_apply(&pd->defaults, o, "popup-style", NULL); + if (style != NULL) { + style_set(&sytmp, &grid_default_cell); + if (style_parse(&sytmp, &pd->defaults, style) == 0) { + pd->defaults.fg = sytmp.gc.fg; + pd->defaults.bg = sytmp.gc.bg; + } + } pd->defaults.attr = 0; pd->px = px; @@ -789,7 +805,7 @@ popup_editor(struct client *c, const char *buf, size_t len, xasprintf(&cmd, "%s %s", editor, path); if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, BOX_LINES_DEFAULT, NULL, px, py, sx, sy, NULL, cmd, 0, NULL, _PATH_TMP, NULL, c, NULL, - popup_editor_close_cb, pe) != 0) { + NULL, NULL, popup_editor_close_cb, pe) != 0) { popup_editor_free(pe); free(cmd); return (-1); diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c index 80050437dbc..55a0c577662 100644 --- a/usr.bin/tmux/screen-write.c +++ b/usr.bin/tmux/screen-write.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-write.c,v 1.203 2021/10/25 09:22:17 nicm Exp $ */ +/* $OpenBSD: screen-write.c,v 1.204 2021/10/25 09:38:36 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -184,9 +184,9 @@ screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx, if (ctx->init_ctx_cb != NULL) { ctx->init_ctx_cb(ctx, ttyctx); if (ttyctx->palette != NULL) { - if (COLOUR_DEFAULT(ttyctx->defaults.fg)) + if (ttyctx->defaults.fg == 8) ttyctx->defaults.fg = ttyctx->palette->fg; - if (COLOUR_DEFAULT(ttyctx->defaults.bg)) + if (ttyctx->defaults.bg == 8) ttyctx->defaults.bg = ttyctx->palette->bg; } } else { diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 831f33000cf..3893657eab2 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.864 2021/10/20 09:50:40 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.865 2021/10/25 09:38:36 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: October 20 2021 $ +.Dd $Mdocdate: October 25 2021 $ .Dt TMUX 1 .Os .Sh NAME @@ -5800,6 +5800,8 @@ forwards any input read from stdin to the empty pane given by .Op Fl d Ar start-directory .Op Fl e Ar environment .Op Fl h Ar height +.Op Fl s Ar style +.Op Fl S Ar border-style .Op Fl t Ar target-pane .Op Fl T Ar title .Op Fl w Ar width @@ -5853,6 +5855,16 @@ See for possible values for .Ar border-lines . .Pp +.Fl s +sets the style for the popup and +.Fl S +sets the style for the popup border. +For how to specify +.Ar style , +see the +.Sx STYLES +section. +.Pp .Fl e takes the form .Ql VARIABLE=value diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 51e1aa02091..93ad82f2115 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1148 2021/10/20 09:50:40 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1149 2021/10/25 09:38:36 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -3155,7 +3155,8 @@ typedef void (*popup_finish_edit_cb)(char *, size_t, void *); int popup_display(int, int, struct cmdq_item *, u_int, u_int, u_int, u_int, struct environ *, const char *, int, char **, const char *, const char *, struct client *, - struct session *, popup_close_cb, void *); + struct session *, const char *, const char *, + popup_close_cb, void *); int popup_editor(struct client *, const char *, size_t, popup_finish_edit_cb, void *); -- 2.20.1