summaryrefslogtreecommitdiffstats
path: root/format-draw.c
diff options
context:
space:
mode:
authornicm <nicm>2019-09-15 21:42:57 +0000
committernicm <nicm>2019-09-15 21:42:57 +0000
commit63e07b245f898af17657c4655f1251aa43e19d0c (patch)
tree6c2db5b222dac64b3804e8b6731fa210f79f4548 /format-draw.c
parenta23ce1b45ff8b8999e2817c9e747188c559725e1 (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 'format-draw.c')
-rw-r--r--format-draw.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/format-draw.c b/format-draw.c
index e0ca89f0..6cced9fd 100644
--- a/format-draw.c
+++ b/format-draw.c
@@ -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: