mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
dynamically fall back to less details
This commit is contained in:
parent
8845d1a7c3
commit
22420c17f7
56
nnn.c
56
nnn.c
|
@ -1186,6 +1186,21 @@ unescape(const char *str)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
int
|
||||
getgoback(struct entry *ent,int sel, int ncols)
|
||||
{
|
||||
const char *c = unescape(ent->name);
|
||||
|
||||
// counts the number of columns before it enounters the filename
|
||||
int count = snprintf(g_buf, ncols, "%s ", CURSYM(sel));
|
||||
|
||||
int goback = 0;
|
||||
while((ncols + goback) > count && mblen(c + (ncols + goback) - count, MB_CUR_MAX) == -1)
|
||||
--goback;
|
||||
|
||||
return goback;
|
||||
}
|
||||
|
||||
static void
|
||||
printent(struct entry *ent, int sel)
|
||||
{
|
||||
|
@ -1206,9 +1221,10 @@ printent(struct entry *ent, int sel)
|
|||
snprintf(g_buf, ncols, "%s%s|", CURSYM(sel), unescape(ent->name));
|
||||
else if (ent->mode & 0100)
|
||||
snprintf(g_buf, ncols, "%s%s*", CURSYM(sel), unescape(ent->name));
|
||||
else
|
||||
snprintf(g_buf, ncols, "%s%s", CURSYM(sel), unescape(ent->name));
|
||||
|
||||
else {
|
||||
int goback = getgoback(ent, sel, ncols);
|
||||
snprintf(g_buf, ncols + goback, "%s%s", CURSYM(sel), unescape(ent->name));
|
||||
}
|
||||
/* Dirs are always shown on top */
|
||||
if (cfg.dircolor && !S_ISDIR(ent->mode)) {
|
||||
attroff(COLOR_PAIR(1) | A_BOLD);
|
||||
|
@ -1242,6 +1258,21 @@ coolsize(off_t size)
|
|||
return size_buf;
|
||||
}
|
||||
|
||||
int
|
||||
getgoback_long(struct entry *ent, int sel, int ncols, char buf[18])
|
||||
{
|
||||
const char *c = unescape(ent->name);
|
||||
|
||||
// counts the number of columns before it enounters the filename
|
||||
int count = snprintf(g_buf, ncols, "%s%-16.16s %8.8s ", CURSYM(sel), buf, coolsize(ent->size));
|
||||
|
||||
int goback = 0;
|
||||
while((ncols + goback) > count && mblen(c + (ncols + goback) - count, MB_CUR_MAX) == -1)
|
||||
--goback;
|
||||
|
||||
return goback;
|
||||
}
|
||||
|
||||
static void
|
||||
printent_long(struct entry *ent, int sel)
|
||||
{
|
||||
|
@ -1253,6 +1284,12 @@ printent_long(struct entry *ent, int sel)
|
|||
else
|
||||
ncols = COLS;
|
||||
|
||||
// if ncols is not enough to accomodate the file details, fall back to the short version
|
||||
if(ncols <= snprintf(g_buf, ncols, "%s%-16.16s %8.8s ", CURSYM(sel), buf, coolsize(ent->size))){
|
||||
printent(ent, sel);
|
||||
return;
|
||||
}
|
||||
|
||||
strftime(buf, 18, "%d-%m-%Y %H:%M", localtime(&ent->t));
|
||||
|
||||
if (sel)
|
||||
|
@ -1273,17 +1310,8 @@ printent_long(struct entry *ent, int sel)
|
|||
snprintf(g_buf, ncols, "%s%-16.16s c %s", CURSYM(sel), buf, unescape(ent->name));
|
||||
else if (ent->mode & 0100)
|
||||
snprintf(g_buf, ncols, "%s%-16.16s %8.8s* %s*", CURSYM(sel), buf, coolsize(ent->size), unescape(ent->name));
|
||||
else
|
||||
{
|
||||
// experimenting in this section
|
||||
const char *c = unescape(ent->name);
|
||||
|
||||
int count = 30;
|
||||
int goback=0;
|
||||
if(ncols+goback>count)
|
||||
while((ncols+goback)>count && mblen(c+(ncols+goback)-count, MB_CUR_MAX)==-1)
|
||||
goback--;
|
||||
|
||||
else {
|
||||
int goback = getgoback_long(ent, sel, ncols, buf);
|
||||
snprintf(g_buf, ncols + goback, "%s%-16.16s %8.8s %s", CURSYM(sel), buf, coolsize(ent->size), unescape(ent->name));
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue