=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/style.c,v retrieving revision 1.17 retrieving revision 1.18 diff -c -r1.17 -r1.18 *** src/usr.bin/tmux/style.c 2019/03/14 21:46:08 1.17 --- src/usr.bin/tmux/style.c 2019/03/18 20:53:33 1.18 *************** *** 1,4 **** ! /* $OpenBSD: style.c,v 1.17 2019/03/14 21:46:08 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: style.c,v 1.18 2019/03/18 20:53:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 19,24 **** --- 19,26 ---- #include + #include + #include #include #include "tmux.h" *************** *** 28,34 **** /* Default style. */ static struct style style_default = { ! { 0, 0, 8, 8, { { ' ' }, 0, 1, 1 } } }; /* --- 30,41 ---- /* Default style. */ static struct style style_default = { ! { 0, 0, 8, 8, { { ' ' }, 0, 1, 1 } }, ! ! STYLE_ALIGN_DEFAULT, ! STYLE_LIST_OFF, ! ! STYLE_RANGE_NONE, 0 }; /* *************** *** 40,47 **** style_parse(struct style *sy, const struct grid_cell *base, const char *in) { struct style saved; ! const char delimiters[] = " ,"; ! char tmp[32]; int value; size_t end; --- 47,54 ---- style_parse(struct style *sy, const struct grid_cell *base, const char *in) { struct style saved; ! const char delimiters[] = " ,", *cp; ! char tmp[256], *found; int value; size_t end; *************** *** 68,73 **** --- 75,134 ---- sy->gc.bg = base->bg; sy->gc.attr = base->attr; sy->gc.flags = base->flags; + } else if (strcasecmp(tmp, "nolist") == 0) + sy->list = STYLE_LIST_OFF; + else if (strncasecmp(tmp, "list=", 5) == 0) { + if (strcasecmp(tmp + 5, "on") == 0) + sy->list = STYLE_LIST_ON; + else if (strcasecmp(tmp + 5, "focus") == 0) + sy->list = STYLE_LIST_FOCUS; + else if (strcasecmp(tmp + 5, "left-marker") == 0) + sy->list = STYLE_LIST_LEFT_MARKER; + else if (strcasecmp(tmp + 5, "right-marker") == 0) + sy->list = STYLE_LIST_RIGHT_MARKER; + else + goto error; + } else if (strcasecmp(tmp, "norange") == 0) { + sy->range_type = style_default.range_type; + sy->range_argument = style_default.range_type; + } else if (end > 6 && strncasecmp(tmp, "range=", 6) == 0) { + found = strchr(tmp + 6, '|'); + if (found != NULL) { + *found++ = '\0'; + if (*found == '\0') + goto error; + for (cp = found; *cp != '\0'; cp++) { + if (!isdigit((u_char)*cp)) + goto error; + } + } + if (strcasecmp(tmp + 6, "left") == 0) { + if (found != NULL) + goto error; + sy->range_type = STYLE_RANGE_LEFT; + sy->range_argument = 0; + } else if (strcasecmp(tmp + 6, "right") == 0) { + if (found != NULL) + goto error; + sy->range_type = STYLE_RANGE_RIGHT; + sy->range_argument = 0; + } else if (strcasecmp(tmp + 6, "window") == 0) { + if (found == NULL) + goto error; + sy->range_type = STYLE_RANGE_WINDOW; + sy->range_argument = atoi(found); + } + } else if (strcasecmp(tmp, "noalign") == 0) + sy->align = style_default.align; + else if (end > 6 && strncasecmp(tmp, "align=", 6) == 0) { + if (strcasecmp(tmp + 6, "left") == 0) + sy->align = STYLE_ALIGN_LEFT; + else if (strcasecmp(tmp + 6, "centre") == 0) + sy->align = STYLE_ALIGN_CENTRE; + else if (strcasecmp(tmp + 6, "right") == 0) + sy->align = STYLE_ALIGN_RIGHT; + else + goto error; } else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) { if ((value = colour_fromstring(tmp + 3)) == -1) goto error; *************** *** 111,121 **** { struct grid_cell *gc = &sy->gc; int off = 0; ! const char *comma = ""; static char s[256]; *s = '\0'; if (gc->fg != 8) { off += xsnprintf(s + off, sizeof s - off, "%sfg=%s", comma, colour_tostring(gc->fg)); --- 172,220 ---- { struct grid_cell *gc = &sy->gc; int off = 0; ! const char *comma = "", *tmp; static char s[256]; + char b[16]; *s = '\0'; + if (sy->list != STYLE_LIST_OFF) { + if (sy->list == STYLE_LIST_ON) + tmp = "on"; + else if (sy->list == STYLE_LIST_FOCUS) + tmp = "focus"; + else if (sy->list == STYLE_LIST_LEFT_MARKER) + tmp = "left-marker"; + else if (sy->list == STYLE_LIST_RIGHT_MARKER) + tmp = "right-marker"; + off += xsnprintf(s + off, sizeof s - off, "%slist=%s", comma, + tmp); + comma = ","; + } + if (sy->range_type != STYLE_RANGE_NONE) { + if (sy->range_type == STYLE_RANGE_LEFT) + tmp = "left"; + else if (sy->range_type == STYLE_RANGE_RIGHT) + tmp = "right"; + else if (sy->range_type == STYLE_RANGE_WINDOW) { + snprintf(b, sizeof b, "window|%u", sy->range_argument); + tmp = b; + } + off += xsnprintf(s + off, sizeof s - off, "%srange=%s", comma, + tmp); + comma = ","; + } + if (sy->align != STYLE_ALIGN_DEFAULT) { + if (sy->align == STYLE_ALIGN_LEFT) + tmp = "left"; + else if (sy->align == STYLE_ALIGN_CENTRE) + tmp = "centre"; + else if (sy->align == STYLE_ALIGN_RIGHT) + tmp = "right"; + off += xsnprintf(s + off, sizeof s - off, "%salign=%s", comma, + tmp); + comma = ","; + } if (gc->fg != 8) { off += xsnprintf(s + off, sizeof s - off, "%sfg=%s", comma, colour_tostring(gc->fg)); *************** *** 180,186 **** memcpy(dst, src, sizeof *dst); } ! /* Check if two styles are the same. */ int style_equal(struct style *sy1, struct style *sy2) { --- 279,285 ---- memcpy(dst, src, sizeof *dst); } ! /* Check if two styles are (visibly) the same. */ int style_equal(struct style *sy1, struct style *sy2) { *************** *** 192,197 **** --- 291,298 ---- if (gc1->bg != gc2->bg) return (0); if ((gc1->attr & STYLE_ATTR_MASK) != (gc2->attr & STYLE_ATTR_MASK)) + return (0); + if (sy1->align != sy2->align) return (0); return (1); }