=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/format.c,v retrieving revision 1.259 retrieving revision 1.260 diff -c -r1.259 -r1.260 *** src/usr.bin/tmux/format.c 2020/06/23 05:23:26 1.259 --- src/usr.bin/tmux/format.c 2020/08/20 16:57:40 1.260 *************** *** 1,4 **** ! /* $OpenBSD: format.c,v 1.259 2020/06/23 05:23:26 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: format.c,v 1.260 2020/08/20 16:57:40 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott *************** *** 94,99 **** --- 94,100 ---- #define FORMAT_WINDOWS 0x100 #define FORMAT_PANES 0x200 #define FORMAT_PRETTY 0x400 + #define FORMAT_LENGTH 0x800 /* Limit on recursion. */ #define FORMAT_LOOP_LIMIT 10 *************** *** 1647,1653 **** /* * Modifiers are a ; separated list of the forms: ! * l,m,C,b,d,t,q,E,T,S,W,P,<,> * =a * =/a * =/a/ --- 1648,1654 ---- /* * Modifiers are a ; separated list of the forms: ! * l,m,C,b,d,n,t,q,E,T,S,W,P,<,> * =a * =/a * =/a/ *************** *** 1664,1670 **** cp++; /* Check single character modifiers with no arguments. */ ! if (strchr("lbdqETSWP<>", cp[0]) != NULL && format_is_end(cp[1])) { format_add_modifier(&list, count, cp, 1, NULL, 0); cp++; --- 1665,1671 ---- 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++; *************** *** 2122,2127 **** --- 2123,2131 ---- case 'd': modifiers |= FORMAT_DIRNAME; break; + case 'n': + modifiers |= FORMAT_LENGTH; + break; case 't': modifiers |= FORMAT_TIMESTRING; if (fm->argc < 1) *************** *** 2301,2313 **** if (value == NULL) value = xstrdup(""); } else { ! /* Neither: look up directly. */ ! value = format_find(ft, copy, modifiers, time_format); ! if (value == NULL) { ! format_log(ft, "format '%s' not found", copy); ! value = xstrdup(""); ! } else ! format_log(ft, "format '%s' found: %s", copy, value); } done: --- 2305,2321 ---- if (value == NULL) value = xstrdup(""); } else { ! if (strstr(copy, "#{") != 0) { ! format_log(ft, "expanding inner format '%s'", copy); ! value = format_expand(ft, copy); ! } else { ! value = format_find(ft, copy, modifiers, time_format); ! if (value == NULL) { ! format_log(ft, "format '%s' not found", copy); ! value = xstrdup(""); ! } else ! format_log(ft, "format '%s' found: %s", copy, value); ! } } done: *************** *** 2316,2323 **** new = format_expand(ft, value); free(value); value = new; ! } ! else if (modifiers & FORMAT_EXPANDTIME) { new = format_expand_time(ft, value); free(value); value = new; --- 2324,2330 ---- new = format_expand(ft, value); free(value); value = new; ! } else if (modifiers & FORMAT_EXPANDTIME) { new = format_expand_time(ft, value); free(value); value = new; *************** *** 2369,2374 **** --- 2376,2389 ---- free(value); value = new; format_log(ft, "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(ft, "replacing with length: %s", new); } /* Expand the buffer and copy in the value. */