From bc0e527f32642cc9eb2354d1bdc033ab6beca33b Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 18 Oct 2018 07:57:57 +0000 Subject: Support for extended underline styles on terminals which offer them, enabled by adding the Smulx capability with terminal-overrides (add something like ',vte*:Smulx=\E[4\:%p1%dm'). GitHub issue 1492. --- attributes.c | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'attributes.c') diff --git a/attributes.c b/attributes.c index 1e45e584..1b831733 100644 --- a/attributes.c +++ b/attributes.c @@ -25,13 +25,13 @@ const char * attributes_tostring(int attr) { - static char buf[128]; + static char buf[512]; size_t len; if (attr == 0) return ("none"); - len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s", + len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s%s%s%s%s", (attr & GRID_ATTR_BRIGHT) ? "bright," : "", (attr & GRID_ATTR_DIM) ? "dim," : "", (attr & GRID_ATTR_UNDERSCORE) ? "underscore," : "", @@ -39,7 +39,11 @@ attributes_tostring(int attr) (attr & GRID_ATTR_REVERSE) ? "reverse," : "", (attr & GRID_ATTR_HIDDEN) ? "hidden," : "", (attr & GRID_ATTR_ITALICS) ? "italics," : "", - (attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : ""); + (attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : "", + (attr & GRID_ATTR_UNDERSCORE_2) ? "double-underscore," : "", + (attr & GRID_ATTR_UNDERSCORE_3) ? "curly-underscore," : "", + (attr & GRID_ATTR_UNDERSCORE_4) ? "dotted-underscore," : "", + (attr & GRID_ATTR_UNDERSCORE_5) ? "dashed-underscore," : ""); if (len > 0) buf[len - 1] = '\0'; @@ -52,6 +56,25 @@ attributes_fromstring(const char *str) const char delimiters[] = " ,|"; int attr; size_t end; + u_int i; + struct { + const char* name; + int attr; + } table[] = { + { "bright", GRID_ATTR_BRIGHT }, + { "bold", GRID_ATTR_BRIGHT }, + { "dim", GRID_ATTR_DIM }, + { "underscore", GRID_ATTR_UNDERSCORE }, + { "blink", GRID_ATTR_BLINK }, + { "reverse", GRID_ATTR_REVERSE }, + { "hidden", GRID_ATTR_HIDDEN }, + { "italics", GRID_ATTR_ITALICS }, + { "strikethrough", GRID_ATTR_STRIKETHROUGH }, + { "double-underscore", GRID_ATTR_UNDERSCORE_2 }, + { "curly-underscore", GRID_ATTR_UNDERSCORE_3 }, + { "dotted-underscore", GRID_ATTR_UNDERSCORE_4 }, + { "dashed-underscore", GRID_ATTR_UNDERSCORE_5 } + }; if (*str == '\0' || strcspn(str, delimiters) == 0) return (-1); @@ -64,24 +87,15 @@ attributes_fromstring(const char *str) attr = 0; do { end = strcspn(str, delimiters); - if ((end == 6 && strncasecmp(str, "bright", end) == 0) || - (end == 4 && strncasecmp(str, "bold", end) == 0)) - attr |= GRID_ATTR_BRIGHT; - else if (end == 3 && strncasecmp(str, "dim", end) == 0) - attr |= GRID_ATTR_DIM; - else if (end == 10 && strncasecmp(str, "underscore", end) == 0) - attr |= GRID_ATTR_UNDERSCORE; - else if (end == 5 && strncasecmp(str, "blink", end) == 0) - attr |= GRID_ATTR_BLINK; - else if (end == 7 && strncasecmp(str, "reverse", end) == 0) - attr |= GRID_ATTR_REVERSE; - else if (end == 6 && strncasecmp(str, "hidden", end) == 0) - attr |= GRID_ATTR_HIDDEN; - else if (end == 7 && strncasecmp(str, "italics", end) == 0) - attr |= GRID_ATTR_ITALICS; - else if (end == 13 && strncasecmp(str, "strikethrough", end) == 0) - attr |= GRID_ATTR_STRIKETHROUGH; - else + for (i = 0; i < nitems(table); i++) { + if (end != strlen(table[i].name)) + continue; + if (strncasecmp(str, table[i].name, end) == 0) { + attr |= table[i].attr; + break; + } + } + if (i == nitems(table)) return (-1); str += end + strspn(str + end, delimiters); } while (*str != '\0'); -- cgit v1.2.3