=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/format.c,v retrieving revision 1.265 retrieving revision 1.266 diff -c -r1.265 -r1.266 *** src/usr.bin/tmux/format.c 2020/11/02 08:21:30 1.265 --- src/usr.bin/tmux/format.c 2020/11/09 09:10:10 1.266 *************** *** 1,4 **** ! /* $OpenBSD: format.c,v 1.265 2020/11/02 08:21:30 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: format.c,v 1.266 2020/11/09 09:10:10 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott *************** *** 98,103 **** --- 98,104 ---- #define FORMAT_PANES 0x200 #define FORMAT_PRETTY 0x400 #define FORMAT_LENGTH 0x800 + #define FORMAT_WIDTH 0x1000 /* Limit on recursion. */ #define FORMAT_LOOP_LIMIT 10 *************** *** 1671,1677 **** /* * Modifiers are a ; separated list of the forms: ! * l,m,C,b,d,n,t,q,E,T,S,W,P,<,> * =a * =/a * =/a/ --- 1672,1678 ---- /* * Modifiers are a ; separated list of the forms: ! * l,m,C,b,d,n,t,w,q,E,T,S,W,P,<,> * =a * =/a * =/a/ *************** *** 1688,1694 **** cp++; /* Check single character modifiers with no arguments. */ ! if (strchr("lbdnqETSWP<>", cp[0]) != NULL && format_is_end(cp[1])) { format_add_modifier(&list, count, cp, 1, NULL, 0); cp++; --- 1689,1695 ---- cp++; /* Check single character modifiers with no arguments. */ ! if (strchr("lbdnqwETSWP<>", cp[0]) != NULL && format_is_end(cp[1])) { format_add_modifier(&list, count, cp, 1, NULL, 0); cp++; *************** *** 2184,2189 **** --- 2185,2193 ---- if (errptr != NULL) width = 0; break; + case 'w': + modifiers |= FORMAT_WIDTH; + break; case 'e': if (fm->argc < 1 || fm->argc > 3) break; *************** *** 2456,2468 **** format_log(es, "applied padding width %d: %s", width, value); } ! /* Replace with the length if needed. */ if (modifiers & FORMAT_LENGTH) { xasprintf(&new, "%zu", strlen(value)); free(value); value = new; format_log(es, "replacing with length: %s", new); } /* Expand the buffer and copy in the value. */ valuelen = strlen(value); --- 2460,2478 ---- format_log(es, "applied padding width %d: %s", width, value); } ! /* Replace with the length or width if needed. */ if (modifiers & FORMAT_LENGTH) { xasprintf(&new, "%zu", strlen(value)); free(value); value = new; format_log(es, "replacing with length: %s", new); } + if (modifiers & FORMAT_WIDTH) { + xasprintf(&new, "%u", format_width(value)); + free(value); + value = new; + format_log(es, "replacing with width: %s", new); + } /* Expand the buffer and copy in the value. */ valuelen = strlen(value); *************** *** 2589,2596 **** break; fmt += n + 1; continue; - case '}': case '#': case ',': format_log(es, "found #%c", ch); while (len - off < 2) { --- 2599,2628 ---- break; fmt += n + 1; continue; case '#': + /* + * If ##[ (with two or more #s), then it is a style and + * can be left for format_draw to handle. + */ + ptr = fmt; + n = 2; + while (*ptr == '#') { + ptr++; + n++; + } + if (*ptr == '[') { + format_log(es, "found #*%zu[", n); + while (len - off < n + 2) { + buf = xreallocarray(buf, 2, len); + len *= 2; + } + memcpy(buf + off, fmt - 2, n + 1); + off += n + 1; + fmt = ptr + 1; + continue; + } + /* FALLTHROUGH */ + case '}': case ',': format_log(es, "found #%c", ch); while (len - off < 2) {