]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #208: cut at correct codepoint for CJK
authorArun Prakash Jana <engineerarun@gmail.com>
Mon, 11 Feb 2019 21:44:08 +0000 (03:14 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Mon, 11 Feb 2019 21:44:08 +0000 (03:14 +0530)
src/nnn.c

index 7602d96ad18411bea3a9baf589cf57180d1641d7..4016b012f4ca9fb03c8059ea7b8654ed738ae893 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1874,7 +1874,7 @@ static char *unescape(const char *str, uint maxcols)
 {
        static wchar_t wbuf[PATH_MAX] __attribute__ ((aligned));
        static wchar_t *buf;
-       static size_t len;
+       static size_t len, lencount;
 
        /* Convert multi-byte to wide char */
        len = mbstowcs(wbuf, str, PATH_MAX);
@@ -1882,11 +1882,12 @@ static char *unescape(const char *str, uint maxcols)
        g_buf[0] = '\0';
        buf = wbuf;
 
-       if (maxcols && len > maxcols) {
-               len = wcswidth(wbuf, len);
-
-               if (len > maxcols)
-                       wbuf[maxcols] = 0;
+       if (maxcols) {
+               len = lencount = wcswidth(wbuf, len);
+               while (len > maxcols) {
+                       wbuf[--lencount] = L'\0';
+                       len = wcswidth(wbuf, lencount);
+               }
        }
 
        while (*buf) {
@@ -2824,7 +2825,7 @@ static void redraw(char *path)
 
        /* Calculate the number of cols available to print entry name */
        if (cfg.showdetail)
-               ncols -= 32;
+               ncols -= 30;
        else
                ncols -= 5;