diff options
author | nicm <nicm> | 2014-01-28 23:07:09 +0000 |
---|---|---|
committer | nicm <nicm> | 2014-01-28 23:07:09 +0000 |
commit | 945339b443affdaaca260605e15b5a3b9a3c6e16 (patch) | |
tree | d04a4ccbdb9d83ded880cda1277911f6cf436197 /options.c | |
parent | c930fd5ff696f5a60e93ed503f0ff57e0bbf6e4d (diff) | |
download | rtmux-945339b443affdaaca260605e15b5a3b9a3c6e16.tar.gz rtmux-945339b443affdaaca260605e15b5a3b9a3c6e16.tar.bz2 rtmux-945339b443affdaaca260605e15b5a3b9a3c6e16.zip |
Allow replacing each of the many sets of separate foo-{fg,bg,attr}
options with a single foo-style option. For example:
set -g status-fg yellow
set -g status-bg red
set -g status-attr blink
Becomes:
set -g status-style fg=yellow,bg=red,blink
The -a flag to set can be used to add to rather than replace a style. So:
set -g status-bg red
Becomes:
set -ag status-style bg=red
Currently this is fully backwards compatible (all *-{fg,bg,attr} options
remain) but the plan is to deprecate them over time.
From Tiago Cunha.
Diffstat (limited to 'options.c')
-rw-r--r-- | options.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -109,6 +109,7 @@ options_set_string(struct options *oo, const char *name, const char *fmt, ...) o = xmalloc(sizeof *o); o->name = xstrdup(name); RB_INSERT(options_tree, &oo->tree, o); + memcpy(&o->style, &grid_default_cell, sizeof o->style); } else if (o->type == OPTIONS_STRING) free(o->str); @@ -140,6 +141,7 @@ options_set_number(struct options *oo, const char *name, long long value) o = xmalloc(sizeof *o); o->name = xstrdup(name); RB_INSERT(options_tree, &oo->tree, o); + memcpy(&o->style, &grid_default_cell, sizeof o->style); } else if (o->type == OPTIONS_STRING) free(o->str); @@ -159,3 +161,37 @@ options_get_number(struct options *oo, const char *name) fatalx("option not a number"); return (o->num); } + +struct options_entry * +options_set_style(struct options *oo, const char *name, const char *value, + int append) +{ + struct options_entry *o; + + if ((o = options_find1(oo, name)) == NULL) { + o = xmalloc(sizeof *o); + o->name = xstrdup(name); + RB_INSERT(options_tree, &oo->tree, o); + } else if (o->type == OPTIONS_STRING) + free(o->str); + + if (!append) + memcpy(&o->style, &grid_default_cell, sizeof o->style); + + o->type = OPTIONS_STYLE; + if (style_parse(&grid_default_cell, &o->style, value) == -1) + return (NULL); + return (o); +} + +struct grid_cell * +options_get_style(struct options *oo, const char *name) +{ + struct options_entry *o; + + if ((o = options_find(oo, name)) == NULL) + fatalx("missing option"); + if (o->type != OPTIONS_STYLE) + fatalx("option not a style"); + return (&o->style); +} |