Avoid double conversion in light mode

This commit is contained in:
Arun Prakash Jana 2019-08-20 21:55:54 +05:30
parent f4f1acf856
commit 505bf0574e
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 15 additions and 7 deletions

View File

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