From ca6b9238a39980aac650eb4bd82ace74c31a285f Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 3 Nov 2011 22:12:12 +0000 Subject: Support for UTF-8 tree drawing (thanks to Bin Guo) --- htop.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'htop.c') diff --git a/htop.c b/htop.c index 10924a1d..b71198a6 100644 --- a/htop.c +++ b/htop.c @@ -263,6 +263,7 @@ int main(int argc, char** argv) { bool userOnly = false; uid_t userId = 0; int usecolors = 1; + TreeType treeType = TREE_TYPE_AUTO; int opt, opti=0; static struct option long_opts[] = @@ -281,8 +282,10 @@ int main(int argc, char** argv) { char *lc_ctype = getenv("LC_CTYPE"); if(lc_ctype != NULL) setlocale(LC_CTYPE, lc_ctype); + else if ((lc_ctype = getenv("LC_ALL"))) + setlocale(LC_CTYPE, lc_ctype); else - setlocale(LC_CTYPE, getenv("LC_ALL")); + setlocale(LC_CTYPE, ""); /* Parse arguments */ while ((opt = getopt_long(argc, argv, "hvCs:d:u:", long_opts, &opti))) { @@ -361,6 +364,34 @@ int main(int argc, char** argv) { settings->delay = delay; if (!usecolors) settings->colorScheme = COLORSCHEME_MONOCHROME; + + if (treeType == TREE_TYPE_AUTO) { +#ifdef HAVE_LIBNCURSESW + char *locale = setlocale(LC_ALL, NULL); + if (locale == NULL || locale[0] == '\0') + locale = setlocale(LC_CTYPE, NULL); + if (locale != NULL && + (strstr(locale, "UTF-8") || + strstr(locale, "utf-8") || + strstr(locale, "UTF8") || + strstr(locale, "utf8"))) + treeType = TREE_TYPE_UTF8; + else + treeType = TREE_TYPE_ASCII; +#else + treeType = TREE_TYPE_ASCII; +#endif + } + switch (treeType) { + default: + case TREE_TYPE_ASCII: + pl->treeStr = ProcessList_treeStrAscii; + break; + case TREE_TYPE_UTF8: + pl->treeStr = ProcessList_treeStrUtf8; + break; + } + CRT_init(settings->delay, settings->colorScheme); -- cgit v1.2.3