From 173e82258fff499849e6152f4f5aa2e5b8f27775 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 26 Oct 2021 12:22:23 +0000 Subject: [PATCH] Do not allow inline styles to replace mode-style for the selected item, from Alexis Hildebrandt in GitHub issue 2946. --- usr.bin/tmux/format-draw.c | 9 +++++++-- usr.bin/tmux/mode-tree.c | 6 +++--- usr.bin/tmux/screen-redraw.c | 4 ++-- usr.bin/tmux/screen-write.c | 10 ++++++---- usr.bin/tmux/status.c | 7 ++++--- usr.bin/tmux/tmux.h | 4 ++-- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/usr.bin/tmux/format-draw.c b/usr.bin/tmux/format-draw.c index 057ad792b55..a80e0893929 100644 --- a/usr.bin/tmux/format-draw.c +++ b/usr.bin/tmux/format-draw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format-draw.c,v 1.24 2021/08/22 15:33:14 nicm Exp $ */ +/* $OpenBSD: format-draw.c,v 1.25 2021/10/26 12:22:23 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott @@ -677,7 +677,8 @@ format_draw_many(struct screen_write_ctx *ctx, struct style *sy, char ch, /* Draw a format to a screen. */ void format_draw(struct screen_write_ctx *octx, const struct grid_cell *base, - u_int available, const char *expanded, struct style_ranges *srs) + u_int available, const char *expanded, struct style_ranges *srs, + int default_colours) { enum { LEFT, CENTRE, @@ -819,6 +820,10 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base, log_debug("%s: style '%s' -> '%s'", __func__, tmp, style_tostring(&sy)); free(tmp); + if (default_colours) { + sy.gc.bg = base->bg; + sy.gc.fg = base->fg; + } /* If this style has a fill colour, store it for later. */ if (sy.fill != 8) diff --git a/usr.bin/tmux/mode-tree.c b/usr.bin/tmux/mode-tree.c index 5c34d5d4f33..1be415605c5 100644 --- a/usr.bin/tmux/mode-tree.c +++ b/usr.bin/tmux/mode-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mode-tree.c,v 1.58 2021/10/20 09:50:40 nicm Exp $ */ +/* $OpenBSD: mode-tree.c,v 1.59 2021/10/26 12:22:23 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott @@ -716,14 +716,14 @@ mode_tree_draw(struct mode_tree_data *mtd) screen_write_nputs(&ctx, w, &gc0, "%s", text); if (mti->text != NULL) { format_draw(&ctx, &gc0, w - width, mti->text, - NULL); + NULL, 0); } } else { screen_write_clearendofline(&ctx, gc.bg); screen_write_nputs(&ctx, w, &gc, "%s", text); if (mti->text != NULL) { format_draw(&ctx, &gc, w - width, mti->text, - NULL); + NULL, 0); } } free(text); diff --git a/usr.bin/tmux/screen-redraw.c b/usr.bin/tmux/screen-redraw.c index 5297062070c..15aa31d2d28 100644 --- a/usr.bin/tmux/screen-redraw.c +++ b/usr.bin/tmux/screen-redraw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-redraw.c,v 1.90 2021/10/14 13:19:01 nicm Exp $ */ +/* $OpenBSD: screen-redraw.c,v 1.91 2021/10/26 12:22:23 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -400,7 +400,7 @@ screen_redraw_make_pane_status(struct client *c, struct window_pane *wp, gc.attr &= ~GRID_ATTR_CHARSET; screen_write_cursormove(&ctx, 0, 0, 0); - format_draw(&ctx, &gc, width, expanded, NULL); + format_draw(&ctx, &gc, width, expanded, NULL, 0); screen_write_stop(&ctx); free(expanded); diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c index 55a0c577662..6af8fb52ae4 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.204 2021/10/25 09:38:36 nicm Exp $ */ +/* $OpenBSD: screen-write.c,v 1.205 2021/10/26 12:22:23 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -665,10 +665,12 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, if (*name == '-') { name++; default_gc.attr |= GRID_ATTR_DIM; - format_draw(ctx, gc, menu->width, name, NULL); + format_draw(ctx, gc, menu->width, name, NULL, + 0); default_gc.attr &= ~GRID_ATTR_DIM; } else - format_draw(ctx, gc, menu->width, name, NULL); + format_draw(ctx, gc, menu->width, name, NULL, + gc == choice_gc); gc = &default_gc; } } @@ -764,7 +766,7 @@ screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny, if (title != NULL) { gc.attr &= ~GRID_ATTR_CHARSET; screen_write_cursormove(ctx, cx + 2, cy, 0); - format_draw(ctx, &gc, nx - 4, title, NULL); + format_draw(ctx, &gc, nx - 4, title, NULL, 0); } screen_write_set_cursor(ctx, cx, cy); diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 827002554b2..bf7274dbc01 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.227 2021/08/20 17:50:42 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.228 2021/10/26 12:22:23 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -439,7 +439,8 @@ status_redraw(struct client *c) screen_write_cursormove(&ctx, 0, i, 0); status_free_ranges(&sle->ranges); - format_draw(&ctx, &gc, width, expanded, &sle->ranges); + format_draw(&ctx, &gc, width, expanded, &sle->ranges, + 0); free(sle->expanded); sle->expanded = expanded; @@ -562,7 +563,7 @@ status_message_redraw(struct client *c) if (c->message_ignore_styles) screen_write_nputs(&ctx, len, &gc, "%s", c->message_string); else - format_draw(&ctx, &gc, c->tty.sx, c->message_string, NULL); + format_draw(&ctx, &gc, c->tty.sx, c->message_string, NULL, 0); screen_write_stop(&ctx); if (grid_compare(sl->active->grid, old_screen.grid) == 0) { diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index f6a9d44b2bc..8929f5de99a 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1150 2021/10/25 21:21:16 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1151 2021/10/26 12:22:23 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -2032,7 +2032,7 @@ char *format_grid_line(struct grid *, u_int); /* format-draw.c */ void format_draw(struct screen_write_ctx *, const struct grid_cell *, u_int, const char *, - struct style_ranges *); + struct style_ranges *, int); u_int format_width(const char *); char *format_trim_left(const char *, u_int); char *format_trim_right(const char *, u_int); -- 2.20.1