=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/format.c,v retrieving revision 1.298 retrieving revision 1.299 diff -c -r1.298 -r1.299 *** src/usr.bin/tmux/format.c 2021/10/11 10:55:30 1.298 --- src/usr.bin/tmux/format.c 2021/10/25 21:21:16 1.299 *************** *** 1,4 **** ! /* $OpenBSD: format.c,v 1.298 2021/10/11 10:55:30 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: format.c,v 1.299 2021/10/25 21:21:16 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott *************** *** 101,106 **** --- 101,107 ---- #define FORMAT_WINDOW_NAME 0x4000 #define FORMAT_SESSION_NAME 0x8000 #define FORMAT_CHARACTER 0x10000 + #define FORMAT_COLOUR 0x20000 /* Limit on recursion. */ #define FORMAT_LOOP_LIMIT 100 *************** *** 3555,3561 **** /* * Modifiers are a ; separated list of the forms: ! * l,m,C,a,b,d,n,t,w,q,E,T,S,W,P,<,> * =a * =/a * =/a/ --- 3556,3562 ---- /* * Modifiers are a ; separated list of the forms: ! * l,m,C,a,b,c,d,n,t,w,q,E,T,S,W,P,<,> * =a * =/a * =/a/ *************** *** 3572,3578 **** cp++; /* Check single character modifiers with no arguments. */ ! if (strchr("labdnwETSWP<>", cp[0]) != NULL && format_is_end(cp[1])) { format_add_modifier(&list, count, cp, 1, NULL, 0); cp++; --- 3573,3579 ---- cp++; /* Check single character modifiers with no arguments. */ ! if (strchr("labcdnwETSWP<>", cp[0]) != NULL && format_is_end(cp[1])) { format_add_modifier(&list, count, cp, 1, NULL, 0); cp++; *************** *** 4052,4061 **** const char *errstr, *copy, *cp, *marker = NULL; const char *time_format = NULL; char *copy0, *condition, *found, *new; ! char *value, *left, *right, c; size_t valuelen; int modifiers = 0, limit = 0, width = 0; ! int j; struct format_modifier *list, *cmp = NULL, *search = NULL; struct format_modifier **sub = NULL, *mexp = NULL, *fm; u_int i, count, nsub = 0; --- 4053,4062 ---- const char *errstr, *copy, *cp, *marker = NULL; const char *time_format = NULL; char *copy0, *condition, *found, *new; ! char *value, *left, *right; size_t valuelen; int modifiers = 0, limit = 0, width = 0; ! int j, c; struct format_modifier *list, *cmp = NULL, *search = NULL; struct format_modifier **sub = NULL, *mexp = NULL, *fm; u_int i, count, nsub = 0; *************** *** 4126,4131 **** --- 4127,4135 ---- case 'b': modifiers |= FORMAT_BASENAME; break; + case 'c': + modifiers |= FORMAT_COLOUR; + break; case 'd': modifiers |= FORMAT_DIRNAME; break; *************** *** 4197,4202 **** --- 4201,4218 ---- value = xstrdup(""); else xasprintf(&value, "%c", c); + free(new); + goto done; + } + + /* Is this a colour? */ + if (modifiers & FORMAT_COLOUR) { + new = format_expand1(es, copy); + c = colour_fromstring(new); + if (c == -1 || (c = colour_force_rgb(c)) == -1) + value = xstrdup(""); + else + xasprintf(&value, "%06x", c & 0xffffff); free(new); goto done; }