]> Sergey Matveev's repositories - nnn.git/commitdiff
Avoid double conversion in light mode
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 20 Aug 2019 16:25:54 +0000 (21:55 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 20 Aug 2019 16:25:54 +0000 (21:55 +0530)
src/nnn.c

index 3458c224cd53483b5aa2378c2814cc07c0ee4c94..1fe6a61b811658fab0f8bdb8538185f3e1e6246b 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -2210,7 +2210,7 @@ static inline void resetdircolor(int flags)
  * it doesn't touch str anymore). Only after that it starts modifying
  * g_buf. This is a phased operation.
  */
-static char *unescape(const char *str, uint maxcols)
+static char *unescape(const char *str, uint maxcols, wchar_t **wstr)
 {
        static wchar_t wbuf[NAME_MAX + 1] __attribute__ ((aligned));
        wchar_t *buf = wbuf;
@@ -2240,6 +2240,11 @@ static char *unescape(const char *str, uint maxcols)
                wbuf[lencount] = L'\0';
        }
 
+       if (wstr) {
+               *wstr = wbuf;
+               return NULL;
+       }
+
        /* Convert wide char to multi-byte */
        wcstombs(g_buf, wbuf, NAME_MAX);
        return g_buf;
@@ -2323,7 +2328,8 @@ static char *coolsize(off_t size)
 
 static void printent(const struct entry *ent, int sel, uint namecols)
 {
-       const char *pname = unescape(ent->name, namecols);
+       wchar_t *wstr;
+       unescape(ent->name, namecols, &wstr);
        const char cp = (ent->flags & FILE_COPIED) ? '+' : ' ';
        char ind[2] = {'\0', '\0'};
        mode_t mode = ent->mode;
@@ -2359,7 +2365,9 @@ static void printent(const struct entry *ent, int sel, uint namecols)
        if (sel)
                attron(A_REVERSE);
 
-       printw("%c%s%s\n", cp, pname, ind);
+       printw("%c", cp);
+       addwstr(wstr);
+       printw("%s\n", ind);
 
        if (sel)
                attroff(A_REVERSE);
@@ -2380,7 +2388,7 @@ static void printent_long(const struct entry *ent, int sel, uint namecols)
        permbuf[3] = '\0';
 
        /* Trim escape chars from name */
-       const char *pname = unescape(ent->name, namecols);
+       const char *pname = unescape(ent->name, namecols, NULL);
 
        /* Directories are always shown on top */
        resetdircolor(ent->flags);
@@ -3280,7 +3288,7 @@ static void redraw(char *path)
                } else
                        ncols -= 35;
        } else
-               ncols -= 5;
+               ncols -= 3;
 
        attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
        cfg.dircolor = 1;
@@ -3309,7 +3317,7 @@ static void redraw(char *path)
                /* We need to show filename as it may be truncated in directory listing */
                if (!cfg.showdetail || !cfg.blkorder)
                        mvprintw(lastln, 0, "%d/%d %s[%s]\n", cur + 1, ndents, sort,
-                                unescape(dents[cur].name, NAME_MAX));
+                                unescape(dents[cur].name, NAME_MAX, NULL));
                else {
                        xstrlcpy(buf, coolsize(dir_blocks << BLK_SHIFT), 12);
                        c = cfg.apparentsz ? 'a' : 'd';
@@ -3317,7 +3325,7 @@ static void redraw(char *path)
                        mvprintw(lastln, 0, "%d/%d %cu: %s (%lu files) free: %s [%s]\n",
                                 cur + 1, ndents, c, buf, num_files,
                                 coolsize(get_fs_info(path, FREE)),
-                                unescape(dents[cur].name, NAME_MAX));
+                                unescape(dents[cur].name, NAME_MAX, NULL));
                }
        } else
                printmsg("0/0");