diff options
author | nicm <nicm> | 2017-05-29 18:06:34 +0000 |
---|---|---|
committer | nicm <nicm> | 2017-05-29 18:06:34 +0000 |
commit | a2ace9da24491c46e704ce6120dcb7e6c9d21c20 (patch) | |
tree | 9727dbdab5ec81ddd11c7ec2ba281439a4b00c4f /format.c | |
parent | 12575014995582b30165d80efa1096eee7622a81 (diff) | |
download | rtmux-a2ace9da24491c46e704ce6120dcb7e6c9d21c20.tar.gz rtmux-a2ace9da24491c46e704ce6120dcb7e6c9d21c20.tar.bz2 rtmux-a2ace9da24491c46e704ce6120dcb7e6c9d21c20.zip |
Add ||, && format operators and C: to search pane content.
Diffstat (limited to 'format.c')
-rw-r--r-- | format.c | 50 |
1 files changed, 39 insertions, 11 deletions
@@ -848,19 +848,17 @@ format_true(const char *s) return (0); } -/* - * Replace a key/value pair in buffer. #{blah} is expanded directly, - * #{?blah,a,b} is replace with a if blah exists and is nonzero else b. - */ +/* Replace a key. */ static int format_replace(struct format_tree *ft, const char *key, size_t keylen, char **buf, size_t *len, size_t *off) { - char *copy, *copy0, *endptr, *ptr, *found, *new, *value; - char *from = NULL, *to = NULL, *left, *right; - size_t valuelen, newlen, fromlen, tolen, used; - long limit = 0; - int modifiers = 0, compare = 0; + struct window_pane *wp = ft->wp; + char *copy, *copy0, *endptr, *ptr, *found, *new; + char *value, *from = NULL, *to = NULL, *left, *right; + size_t valuelen, newlen, fromlen, tolen, used; + long limit = 0; + int modifiers = 0, compare = 0, search = 0; /* Make a copy of the key. */ copy0 = copy = xmalloc(keylen + 1); @@ -875,6 +873,24 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, compare = -2; copy += 2; break; + case 'C': + if (copy[1] != ':') + break; + search = 1; + copy += 2; + break; + case '|': + if (copy[1] != '|' || copy[2] != ':') + break; + compare = -3; + copy += 3; + break; + case '&': + if (copy[1] != '&' || copy[2] != ':') + break; + compare = -4; + copy += 3; + break; case '!': if (copy[1] == '=' && copy[2] == ':') { compare = -1; @@ -940,13 +956,25 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, } /* Is this a comparison or a conditional? */ - if (compare != 0) { + if (search) { + /* Search in pane. */ + if (wp == NULL) + value = xstrdup("0"); + else + xasprintf(&value, "%u", window_pane_search(wp, copy)); + } else if (compare != 0) { /* Comparison: compare comma-separated left and right. */ if (format_choose(copy, &left, &right) != 0) goto fail; left = format_expand(ft, left); right = format_expand(ft, right); - if (compare == 1 && strcmp(left, right) == 0) + if (compare == -3 && + (format_true(left) || format_true(right))) + value = xstrdup("1"); + else if (compare == -4 && + (format_true(left) && format_true(right))) + value = xstrdup("1"); + else if (compare == 1 && strcmp(left, right) == 0) value = xstrdup("1"); else if (compare == -1 && strcmp(left, right) != 0) value = xstrdup("1"); |