diff options
author | 2014-01-28 23:07:09 +0000 | |
---|---|---|
committer | 2014-01-28 23:07:09 +0000 | |
commit | a8c9f8391cc553aa4d86398b1dedfc0f0cb99cfa (patch) | |
tree | 7fcb188a22aabd5f7dcd3e873c2bfcdcf93c9f0a /usr.bin/tmux/options.c | |
parent | typo in errx() string (diff) | |
download | wireguard-openbsd-a8c9f8391cc553aa4d86398b1dedfc0f0cb99cfa.tar.xz wireguard-openbsd-a8c9f8391cc553aa4d86398b1dedfc0f0cb99cfa.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 'usr.bin/tmux/options.c')
-rw-r--r-- | usr.bin/tmux/options.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/usr.bin/tmux/options.c b/usr.bin/tmux/options.c index a37558717a3..b67d94ad703 100644 --- a/usr.bin/tmux/options.c +++ b/usr.bin/tmux/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.9 2014/01/09 13:58:06 nicm Exp $ */ +/* $OpenBSD: options.c,v 1.10 2014/01/28 23:07:09 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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); +} |