=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/options.c,v retrieving revision 1.55 retrieving revision 1.56 diff -c -r1.55 -r1.56 *** src/usr.bin/tmux/options.c 2019/12/03 10:47:22 1.55 --- src/usr.bin/tmux/options.c 2020/05/16 15:01:31 1.56 *************** *** 1,4 **** ! /* $OpenBSD: options.c,v 1.55 2019/12/03 10:47:22 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: options.c,v 1.56 2020/05/16 15:01:31 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott *************** *** 53,58 **** --- 53,61 ---- const struct options_table_entry *tableentry; union options_value value; + int cached; + struct style style; + RB_ENTRY(options_entry) entry; }; *************** *** 73,81 **** (o)->tableentry->type == OPTIONS_TABLE_COLOUR || \ (o)->tableentry->type == OPTIONS_TABLE_FLAG || \ (o)->tableentry->type == OPTIONS_TABLE_CHOICE)) - #define OPTIONS_IS_STYLE(o) \ - ((o)->tableentry != NULL && \ - (o)->tableentry->type == OPTIONS_TABLE_STYLE) #define OPTIONS_IS_COMMAND(o) \ ((o)->tableentry != NULL && \ (o)->tableentry->type == OPTIONS_TABLE_COMMAND) --- 76,81 ---- *************** *** 123,130 **** if (OPTIONS_IS_COMMAND(o)) return (cmd_list_print(ov->cmdlist, 0)); - if (OPTIONS_IS_STYLE(o)) - return (xstrdup(style_tostring(&ov->style))); if (OPTIONS_IS_NUMBER(o)) { switch (o->tableentry->type) { case OPTIONS_TABLE_NUMBER: --- 123,128 ---- *************** *** 146,152 **** s = xstrdup(o->tableentry->choices[ov->number]); break; case OPTIONS_TABLE_STRING: - case OPTIONS_TABLE_STYLE: case OPTIONS_TABLE_COMMAND: fatalx("not a number option type"); } --- 144,149 ---- *************** *** 258,267 **** case OPTIONS_TABLE_STRING: ov->string = xstrdup(oe->default_str); break; - case OPTIONS_TABLE_STYLE: - style_set(&ov->style, &grid_default_cell); - style_parse(&ov->style, &grid_default_cell, oe->default_str); - break; default: ov->number = oe->default_num; break; --- 255,260 ---- *************** *** 653,677 **** return (o->value.number); } - struct style * - options_get_style(struct options *oo, const char *name) - { - struct options_entry *o; - - o = options_get(oo, name); - if (o == NULL) - fatalx("missing option %s", name); - if (!OPTIONS_IS_STYLE(o)) - fatalx("option %s is not a style", name); - return (&o->value.style); - } - struct options_entry * options_set_string(struct options *oo, const char *name, int append, const char *fmt, ...) { struct options_entry *o; va_list ap; char *s, *value; va_start(ap, fmt); --- 646,658 ---- return (o->value.number); } struct options_entry * options_set_string(struct options *oo, const char *name, int append, const char *fmt, ...) { struct options_entry *o; va_list ap; + const char *separator = ""; char *s, *value; va_start(ap, fmt); *************** *** 680,686 **** o = options_get_only(oo, name); if (o != NULL && append && OPTIONS_IS_STRING(o)) { ! xasprintf(&value, "%s%s", o->value.string, s); free(s); } else value = s; --- 661,672 ---- o = options_get_only(oo, name); if (o != NULL && append && OPTIONS_IS_STRING(o)) { ! if (*name != '@') { ! separator = o->tableentry->separator; ! if (separator == NULL) ! separator = ""; ! } ! xasprintf(&value, "%s%s%s", o->value.string, separator, s); free(s); } else value = s; *************** *** 696,701 **** --- 682,688 ---- fatalx("option %s is not a string", name); free(o->value.string); o->value.string = value; + o->cached = 0; return (o); } *************** *** 720,754 **** return (o); } - struct options_entry * - options_set_style(struct options *oo, const char *name, int append, - const char *value) - { - struct options_entry *o; - struct style sy; - - if (*name == '@') - fatalx("user option %s must be a string", name); - - o = options_get_only(oo, name); - if (o != NULL && append && OPTIONS_IS_STYLE(o)) - style_copy(&sy, &o->value.style); - else - style_set(&sy, &grid_default_cell); - if (style_parse(&sy, &grid_default_cell, value) == -1) - return (NULL); - if (o == NULL) { - o = options_default(oo, options_parent_table_entry(oo, name)); - if (o == NULL) - return (NULL); - } - - if (!OPTIONS_IS_STYLE(o)) - fatalx("option %s is not a style", name); - style_copy(&o->value.style, &sy); - return (o); - } - int options_scope_from_name(struct args *args, int window, const char *name, struct cmd_find_state *fs, struct options **oo, --- 707,712 ---- *************** *** 873,876 **** --- 831,868 ---- *oo = s->options; return (OPTIONS_TABLE_SESSION); } + } + + struct style * + options_string_to_style(struct options *oo, const char *name, + struct format_tree *ft) + { + struct options_entry *o; + const char *s; + char *expanded; + + o = options_get(oo, name); + if (o == NULL || !OPTIONS_IS_STRING(o)) + return (NULL); + + if (o->cached) + return (&o->style); + s = o->value.string; + log_debug("%s: %s is '%s'", __func__, name, s); + + style_set(&o->style, &grid_default_cell); + o->cached = (strstr(s, "#{") == NULL); + + if (ft != NULL && !o->cached) { + expanded = format_expand(ft, s); + if (style_parse(&o->style, &grid_default_cell, expanded) != 0) { + free(expanded); + return (NULL); + } + free(expanded); + } else { + if (style_parse(&o->style, &grid_default_cell, s) != 0) + return (NULL); + } + return (&o->style); }