tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is

UTF-8. Also try to make the existing checks more readable.
This commit is contained in:
nicm 2015-11-12 11:24:08 +00:00
parent c41673f3fa
commit 0cc812ae34

30
tmux.c
View File

@ -191,7 +191,8 @@ find_home(void)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
char *s, *path, *label, **var, tmp[PATH_MAX]; char *path, *label, **var, tmp[PATH_MAX];
const char *s;
int opt, flags, keys; int opt, flags, keys;
#ifdef DEBUG #ifdef DEBUG
@ -258,20 +259,25 @@ main(int argc, char **argv)
"proc exec tty ps", NULL) != 0) "proc exec tty ps", NULL) != 0)
err(1, "pledge"); err(1, "pledge");
if (!(flags & CLIENT_UTF8)) {
/* /*
* If the user has set whichever of LC_ALL, LC_CTYPE or LANG * tmux is a UTF-8 terminal, so if TMUX is set, assume UTF-8.
* exist (in that order) to contain UTF-8, it is a safe * Otherwise, if the user has set LC_ALL, LC_CTYPE or LANG to contain
* assumption that either they are using a UTF-8 terminal, or * UTF-8, it is a safe assumption that either they are using a UTF-8
* if not they know that output from UTF-8-capable programs may * terminal, or if not they know that output from UTF-8-capable
* be wrong. * programs may be wrong.
*/ */
if ((s = getenv("LC_ALL")) == NULL || *s == '\0') { if (getenv("TMUX") != NULL)
if ((s = getenv("LC_CTYPE")) == NULL || *s == '\0') flags |= CLIENT_UTF8;
else {
s = getenv("LC_ALL");
if (s == NULL || *s == '\0')
s = getenv("LC_CTYPE");
if (s == NULL || *s == '\0')
s = getenv("LANG"); s = getenv("LANG");
} if (s == NULL || *s == '\0')
if (s != NULL && (strcasestr(s, "UTF-8") != NULL || s = "";
strcasestr(s, "UTF8") != NULL)) if (strcasestr(s, "UTF-8") != NULL ||
strcasestr(s, "UTF8") != NULL)
flags |= CLIENT_UTF8; flags |= CLIENT_UTF8;
} }