summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/attributes.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2018-10-18 07:57:57 +0000
committernicm <nicm@openbsd.org>2018-10-18 07:57:57 +0000
commit42caa3399e0524340f9e4fb3e0677d185af4dd31 (patch)
tree7b996e92c90b1a2756bdd984193fe1d1e5af9d73 /usr.bin/tmux/attributes.c
parentFix not accounting for NUL for allocation size and move to reallocarray (diff)
downloadwireguard-openbsd-42caa3399e0524340f9e4fb3e0677d185af4dd31.tar.xz
wireguard-openbsd-42caa3399e0524340f9e4fb3e0677d185af4dd31.zip
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.
Diffstat (limited to 'usr.bin/tmux/attributes.c')
-rw-r--r--usr.bin/tmux/attributes.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/usr.bin/tmux/attributes.c b/usr.bin/tmux/attributes.c
index b51858b165a..ec47e8d2672 100644
--- a/usr.bin/tmux/attributes.c
+++ b/usr.bin/tmux/attributes.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: attributes.c,v 1.7 2017/03/22 07:16:54 nicm Exp $ */
+/* $OpenBSD: attributes.c,v 1.8 2018/10/18 07:57:57 nicm Exp $ */
/*
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
@@ -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');