mirror of
https://github.com/tmux/tmux.git
synced 2025-09-02 05:21:10 +00:00
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.
This commit is contained in:
36
options.c
36
options.c
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user