summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/format-draw.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2019-09-15 21:42:58 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2019-09-15 21:42:58 +0000
commit889e8da8436721c8711f4ff08523abab7bada785 (patch)
tree0d1d06a88b95d392e3df7a33fda98f65ccfa36b2 /usr.bin/tmux/format-draw.c
parentbea0d1124c99f859f85f5104779e462e8a79f6d4 (diff)
Add push-default and pop-default in styles to change the default colours
and attributes and use them to restore the previous behaviour of window-status-style being the default for window-status-format in the status line. From John Drouhard in GitHub issue 1912.
Diffstat (limited to 'usr.bin/tmux/format-draw.c')
-rw-r--r--usr.bin/tmux/format-draw.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/usr.bin/tmux/format-draw.c b/usr.bin/tmux/format-draw.c
index d1023deb1c3..441bfe7fc4e 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.12 2019/07/06 20:37:29 nicm Exp $ */
+/* $OpenBSD: format-draw.c,v 1.13 2019/09/15 21:42:57 nicm Exp $ */
/*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -513,8 +513,8 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
int focus_start = -1, focus_end = -1;
int list_state = -1, fill = -1;
enum style_align list_align = STYLE_ALIGN_DEFAULT;
- struct grid_cell gc;
- struct style sy;
+ struct grid_cell gc, current_default;
+ struct style sy, saved_sy;
struct utf8_data *ud = &sy.gc.data;
const char *cp, *end;
enum utf8_state more;
@@ -523,7 +523,8 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
struct format_ranges frs;
struct style_range *sr;
- style_set(&sy, base);
+ memcpy(&current_default, base, sizeof current_default);
+ style_set(&sy, &current_default);
TAILQ_INIT(&frs);
log_debug("%s: %s", __func__, expanded);
@@ -535,7 +536,7 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
for (i = 0; i < TOTAL; i++) {
screen_init(&s[i], size, 1, 0);
screen_write_start(&ctx[i], NULL, &s[i]);
- screen_write_clearendofline(&ctx[i], base->bg);
+ screen_write_clearendofline(&ctx[i], current_default.bg);
width[i] = 0;
}
@@ -581,7 +582,8 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
goto out;
}
tmp = xstrndup(cp + 2, end - (cp + 2));
- if (style_parse(&sy, base, tmp) != 0) {
+ style_copy(&saved_sy, &sy);
+ if (style_parse(&sy, &current_default, tmp) != 0) {
log_debug("%s: invalid style '%s'", __func__, tmp);
free(tmp);
cp = end + 1;
@@ -595,6 +597,15 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
if (sy.fill != 8)
fill = sy.fill;
+ /* If this style pushed or popped the default, update it. */
+ if (sy.default_type == STYLE_DEFAULT_PUSH) {
+ memcpy(&current_default, &saved_sy.gc, sizeof current_default);
+ sy.default_type = STYLE_DEFAULT_BASE;
+ } else if (sy.default_type == STYLE_DEFAULT_POP) {
+ memcpy(&current_default, base, sizeof current_default);
+ sy.default_type = STYLE_DEFAULT_BASE;
+ }
+
/* Check the list state. */
switch (sy.list) {
case STYLE_LIST_ON: