Add a helper function for the most common format_create/defaults/expand

pattern.
This commit is contained in:
nicm
2017-03-08 13:36:12 +00:00
parent 1e6e606f54
commit 6b2009ad72
11 changed files with 49 additions and 89 deletions

View File

@ -500,7 +500,6 @@ format_merge(struct format_tree *ft, struct format_tree *from)
if (fe->value != NULL)
format_add(ft, fe->key, "%s", fe->value);
}
}
/* Create a new tree. */
@ -1061,6 +1060,22 @@ format_expand(struct format_tree *ft, const char *fmt)
return (buf);
}
/* Expand a single string. */
char *
format_single(struct cmdq_item *item, const char *fmt, struct client *c,
struct session *s, struct winlink *wl, struct window_pane *wp)
{
struct format_tree *ft;
char *expanded;
ft = format_create(item, FORMAT_NONE, 0);
format_defaults(ft, c, s, wl, wp);
expanded = format_expand(ft, fmt);
format_free(ft);
return (expanded);
}
/* Set defaults for any of arguments that are not NULL. */
void
format_defaults(struct format_tree *ft, struct client *c, struct session *s,