diff options
Diffstat (limited to 'utf8.c')
-rw-r--r-- | utf8.c | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -22,7 +22,6 @@ #include <errno.h> #include <stdlib.h> #include <string.h> -#include <vis.h> #include <wchar.h> #include "tmux.h" @@ -217,7 +216,11 @@ utf8_width(struct utf8_data *ud, int *width) { wchar_t wc; +#ifdef HAVE_UTF8PROC + switch (utf8proc_mbtowc(&wc, ud->data, ud->size)) { +#else switch (mbtowc(&wc, ud->data, ud->size)) { +#endif case -1: log_debug("UTF-8 %.*s, mbtowc() %d", (int)ud->size, ud->data, errno); @@ -226,13 +229,30 @@ utf8_width(struct utf8_data *ud, int *width) case 0: return (UTF8_ERROR); } +#ifdef HAVE_UTF8PROC + *width = utf8proc_wcwidth(wc); +#else *width = wcwidth(wc); - if (*width < 0 || *width > 0xff) { - log_debug("UTF-8 %.*s, wcwidth() %d", (int)ud->size, ud->data, - *width); - return (UTF8_ERROR); +#endif + if (*width >= 0 && *width <= 0xff) + return (UTF8_DONE); + log_debug("UTF-8 %.*s, wcwidth() %d", (int)ud->size, ud->data, *width); + +#ifndef __OpenBSD__ + /* + * Many platforms (particularly and inevitably OS X) have no width for + * relatively common characters (wcwidth() returns -1); assume width 1 + * in this case. This will be wrong for genuinely nonprintable + * characters, but they should be rare. We may pass through stuff that + * ideally we would block, but this is no worse than sending the same + * to the terminal without tmux. + */ + if (*width < 0) { + *width = 1; + return (UTF8_DONE); } - return (UTF8_DONE); +#endif + return (UTF8_ERROR); } /* |