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
60
nnn.c
60
nnn.c
|
@ -1186,6 +1186,21 @@ unescape(const char *str)
|
||||||
return buffer;
|
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
|
static void
|
||||||
printent(struct entry *ent, int sel)
|
printent(struct entry *ent, int sel)
|
||||||
{
|
{
|
||||||
|
@ -1197,7 +1212,7 @@ printent(struct entry *ent, int sel)
|
||||||
ncols = COLS;
|
ncols = COLS;
|
||||||
|
|
||||||
if (S_ISDIR(ent->mode))
|
if (S_ISDIR(ent->mode))
|
||||||
snprintf(g_buf, ncols, "%s%s/", CURSYM(sel), unescape(ent->name));
|
snprintf(g_buf, ncols, "%s%s/", CURSYM(sel), unescape(ent->name));
|
||||||
else if (S_ISLNK(ent->mode))
|
else if (S_ISLNK(ent->mode))
|
||||||
snprintf(g_buf, ncols, "%s%s@", CURSYM(sel), unescape(ent->name));
|
snprintf(g_buf, ncols, "%s%s@", CURSYM(sel), unescape(ent->name));
|
||||||
else if (S_ISSOCK(ent->mode))
|
else if (S_ISSOCK(ent->mode))
|
||||||
|
@ -1206,9 +1221,10 @@ printent(struct entry *ent, int sel)
|
||||||
snprintf(g_buf, ncols, "%s%s|", CURSYM(sel), unescape(ent->name));
|
snprintf(g_buf, ncols, "%s%s|", CURSYM(sel), unescape(ent->name));
|
||||||
else if (ent->mode & 0100)
|
else if (ent->mode & 0100)
|
||||||
snprintf(g_buf, ncols, "%s%s*", CURSYM(sel), unescape(ent->name));
|
snprintf(g_buf, ncols, "%s%s*", CURSYM(sel), unescape(ent->name));
|
||||||
else
|
else {
|
||||||
snprintf(g_buf, ncols, "%s%s", CURSYM(sel), unescape(ent->name));
|
int goback = getgoback(ent, sel, ncols);
|
||||||
|
snprintf(g_buf, ncols + goback, "%s%s", CURSYM(sel), unescape(ent->name));
|
||||||
|
}
|
||||||
/* Dirs are always shown on top */
|
/* Dirs are always shown on top */
|
||||||
if (cfg.dircolor && !S_ISDIR(ent->mode)) {
|
if (cfg.dircolor && !S_ISDIR(ent->mode)) {
|
||||||
attroff(COLOR_PAIR(1) | A_BOLD);
|
attroff(COLOR_PAIR(1) | A_BOLD);
|
||||||
|
@ -1242,6 +1258,21 @@ coolsize(off_t size)
|
||||||
return size_buf;
|
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
|
static void
|
||||||
printent_long(struct entry *ent, int sel)
|
printent_long(struct entry *ent, int sel)
|
||||||
{
|
{
|
||||||
|
@ -1253,6 +1284,12 @@ printent_long(struct entry *ent, int sel)
|
||||||
else
|
else
|
||||||
ncols = COLS;
|
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));
|
strftime(buf, 18, "%d-%m-%Y %H:%M", localtime(&ent->t));
|
||||||
|
|
||||||
if (sel)
|
if (sel)
|
||||||
|
@ -1273,18 +1310,9 @@ printent_long(struct entry *ent, int sel)
|
||||||
snprintf(g_buf, ncols, "%s%-16.16s c %s", CURSYM(sel), buf, unescape(ent->name));
|
snprintf(g_buf, ncols, "%s%-16.16s c %s", CURSYM(sel), buf, unescape(ent->name));
|
||||||
else if (ent->mode & 0100)
|
else if (ent->mode & 0100)
|
||||||
snprintf(g_buf, ncols, "%s%-16.16s %8.8s* %s*", CURSYM(sel), buf, coolsize(ent->size), unescape(ent->name));
|
snprintf(g_buf, ncols, "%s%-16.16s %8.8s* %s*", CURSYM(sel), buf, coolsize(ent->size), unescape(ent->name));
|
||||||
else
|
else {
|
||||||
{
|
int goback = getgoback_long(ent, sel, ncols, buf);
|
||||||
// experimenting in this section
|
snprintf(g_buf, ncols + goback, "%s%-16.16s %8.8s %s", CURSYM(sel), buf, coolsize(ent->size), unescape(ent->name));
|
||||||
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--;
|
|
||||||
|
|
||||||
snprintf(g_buf, ncols+goback, "%s%-16.16s %8.8s %s", CURSYM(sel), buf, coolsize(ent->size), unescape(ent->name));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (S_ISDIR(ent->mode))
|
if (S_ISDIR(ent->mode))
|
||||||
|
|
Loading…
Reference in a new issue