mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
Wrap etries within same line
This commit is contained in:
parent
f4abfc2af9
commit
4f17c6bd65
134
nnn.c
134
nnn.c
|
@ -187,27 +187,12 @@ max_openfds()
|
||||||
return 32;
|
return 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
/* Just a safe strncpy(3) */
|
||||||
|
static void
|
||||||
xstrlcpy(char *dest, const char *src, size_t n)
|
xstrlcpy(char *dest, const char *src, size_t n)
|
||||||
{
|
{
|
||||||
size_t i;
|
strncpy(dest, src, n - 1);
|
||||||
|
dest[n - 1] = '\0';
|
||||||
for (i = 0; i < n && *src; i++)
|
|
||||||
*dest++ = *src++;
|
|
||||||
|
|
||||||
if (n) {
|
|
||||||
*dest = '\0';
|
|
||||||
|
|
||||||
#ifdef CHECK_XSTRLCPY_RET
|
|
||||||
/* Compiling this out as we are not checking
|
|
||||||
the return value anywhere (controlled case).
|
|
||||||
Just returning the number of bytes copied. */
|
|
||||||
while(*src++)
|
|
||||||
i++;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -615,18 +600,28 @@ mkpath(char *dir, char *name, char *out, size_t n)
|
||||||
static void
|
static void
|
||||||
printent(struct entry *ent, int active)
|
printent(struct entry *ent, int active)
|
||||||
{
|
{
|
||||||
if (S_ISDIR(ent->mode))
|
static int ncols;
|
||||||
printw("%s%s/\n", CURSYM(active), ent->name);
|
static char str[PATH_MAX + 16];
|
||||||
else if (S_ISLNK(ent->mode))
|
|
||||||
printw("%s%s@\n", CURSYM(active), ent->name);
|
if (COLS > PATH_MAX + 16)
|
||||||
else if (S_ISSOCK(ent->mode))
|
ncols = PATH_MAX + 16;
|
||||||
printw("%s%s=\n", CURSYM(active), ent->name);
|
|
||||||
else if (S_ISFIFO(ent->mode))
|
|
||||||
printw("%s%s|\n", CURSYM(active), ent->name);
|
|
||||||
else if (ent->mode & S_IXUSR)
|
|
||||||
printw("%s%s*\n", CURSYM(active), ent->name);
|
|
||||||
else
|
else
|
||||||
printw("%s%s\n", CURSYM(active), ent->name);
|
ncols = COLS;
|
||||||
|
|
||||||
|
if (S_ISDIR(ent->mode))
|
||||||
|
snprintf(str, ncols, "%s%s/", CURSYM(active), ent->name);
|
||||||
|
else if (S_ISLNK(ent->mode))
|
||||||
|
snprintf(str, ncols, "%s%s@", CURSYM(active), ent->name);
|
||||||
|
else if (S_ISSOCK(ent->mode))
|
||||||
|
snprintf(str, ncols, "%s%s=", CURSYM(active), ent->name);
|
||||||
|
else if (S_ISFIFO(ent->mode))
|
||||||
|
snprintf(str, ncols, "%s%s|", CURSYM(active), ent->name);
|
||||||
|
else if (ent->mode & S_IXUSR)
|
||||||
|
snprintf(str, ncols, "%s%s*", CURSYM(active), ent->name);
|
||||||
|
else
|
||||||
|
snprintf(str, ncols, "%s%s", CURSYM(active), ent->name);
|
||||||
|
|
||||||
|
printw("%s\n", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void (*printptr)(struct entry *ent, int active) = &printent;
|
static void (*printptr)(struct entry *ent, int active) = &printent;
|
||||||
|
@ -658,7 +653,15 @@ coolsize(off_t size)
|
||||||
static void
|
static void
|
||||||
printent_long(struct entry *ent, int active)
|
printent_long(struct entry *ent, int active)
|
||||||
{
|
{
|
||||||
|
static int ncols;
|
||||||
|
static char str[PATH_MAX + 32];
|
||||||
static char buf[18];
|
static char buf[18];
|
||||||
|
|
||||||
|
if (COLS > PATH_MAX + 32)
|
||||||
|
ncols = PATH_MAX + 32;
|
||||||
|
else
|
||||||
|
ncols = COLS;
|
||||||
|
|
||||||
strftime(buf, 18, "%d %m %Y %H:%M", localtime(&ent->t));
|
strftime(buf, 18, "%d %m %Y %H:%M", localtime(&ent->t));
|
||||||
|
|
||||||
if (active)
|
if (active)
|
||||||
|
@ -666,56 +669,58 @@ printent_long(struct entry *ent, int active)
|
||||||
|
|
||||||
if (!bsizeorder) {
|
if (!bsizeorder) {
|
||||||
if (S_ISDIR(ent->mode))
|
if (S_ISDIR(ent->mode))
|
||||||
printw("%s%-16.16s / %s/\n",
|
snprintf(str, ncols, "%s%-16.16s / %s/",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (S_ISLNK(ent->mode))
|
else if (S_ISLNK(ent->mode))
|
||||||
printw("%s%-16.16s @ %s@\n",
|
snprintf(str, ncols, "%s%-16.16s @ %s@",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (S_ISSOCK(ent->mode))
|
else if (S_ISSOCK(ent->mode))
|
||||||
printw("%s%-16.16s = %s=\n",
|
snprintf(str, ncols, "%s%-16.16s = %s=",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (S_ISFIFO(ent->mode))
|
else if (S_ISFIFO(ent->mode))
|
||||||
printw("%s%-16.16s | %s|\n",
|
snprintf(str, ncols, "%s%-16.16s | %s|",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (S_ISBLK(ent->mode))
|
else if (S_ISBLK(ent->mode))
|
||||||
printw("%s%-16.16s b %s\n",
|
snprintf(str, ncols, "%s%-16.16s b %s",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (S_ISCHR(ent->mode))
|
else if (S_ISCHR(ent->mode))
|
||||||
printw("%s%-16.16s c %s\n",
|
snprintf(str, ncols, "%s%-16.16s c %s",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (ent->mode & S_IXUSR)
|
else if (ent->mode & S_IXUSR)
|
||||||
printw("%s%-16.16s %8.8s* %s*\n", CURSYM(active),
|
snprintf(str, ncols, "%s%-16.16s %8.8s* %s*",
|
||||||
buf, coolsize(ent->size), ent->name);
|
CURSYM(active), buf, coolsize(ent->size), ent->name);
|
||||||
else
|
else
|
||||||
printw("%s%-16.16s %8.8s %s\n", CURSYM(active),
|
snprintf(str, ncols, "%s%-16.16s %8.8s %s",
|
||||||
buf, coolsize(ent->size), ent->name);
|
CURSYM(active), buf, coolsize(ent->size), ent->name);
|
||||||
} else {
|
} else {
|
||||||
if (S_ISDIR(ent->mode))
|
if (S_ISDIR(ent->mode))
|
||||||
printw("%s%-16.16s %8.8s/ %s/\n", CURSYM(active),
|
snprintf(str, ncols, "%s%-16.16s %8.8s/ %s/",
|
||||||
buf, coolsize(ent->bsize << 9), ent->name);
|
CURSYM(active), buf, coolsize(ent->bsize << 9), ent->name);
|
||||||
else if (S_ISLNK(ent->mode))
|
else if (S_ISLNK(ent->mode))
|
||||||
printw("%s%-16.16s @ %s@\n",
|
snprintf(str, ncols, "%s%-16.16s @ %s@",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (S_ISSOCK(ent->mode))
|
else if (S_ISSOCK(ent->mode))
|
||||||
printw("%s%-16.16s = %s=\n",
|
snprintf(str, ncols, "%s%-16.16s = %s=",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (S_ISFIFO(ent->mode))
|
else if (S_ISFIFO(ent->mode))
|
||||||
printw("%s%-16.16s | %s|\n",
|
snprintf(str, ncols, "%s%-16.16s | %s|",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (S_ISBLK(ent->mode))
|
else if (S_ISBLK(ent->mode))
|
||||||
printw("%s%-16.16s b %s\n",
|
snprintf(str, ncols, "%s%-16.16s b %s",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (S_ISCHR(ent->mode))
|
else if (S_ISCHR(ent->mode))
|
||||||
printw("%s%-16.16s c %s\n",
|
snprintf(str, ncols, "%s%-16.16s c %s",
|
||||||
CURSYM(active), buf, ent->name);
|
CURSYM(active), buf, ent->name);
|
||||||
else if (ent->mode & S_IXUSR)
|
else if (ent->mode & S_IXUSR)
|
||||||
printw("%s%-16.16s %8.8s* %s*\n", CURSYM(active),
|
snprintf(str, ncols, "%s%-16.16s %8.8s* %s*",
|
||||||
buf, coolsize(ent->bsize << 9), ent->name);
|
CURSYM(active), buf, coolsize(ent->bsize << 9), ent->name);
|
||||||
else
|
else
|
||||||
printw("%s%-16.16s %8.8s %s\n", CURSYM(active),
|
snprintf(str, ncols, "%s%-16.16s %8.8s %s",
|
||||||
buf, coolsize(ent->bsize << 9), ent->name);
|
CURSYM(active), buf, coolsize(ent->bsize << 9), ent->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printw("%s\n", str);
|
||||||
|
|
||||||
if (active)
|
if (active)
|
||||||
attroff(A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
}
|
}
|
||||||
|
@ -1179,6 +1184,7 @@ redraw(char *path)
|
||||||
static char cwd[PATH_MAX];
|
static char cwd[PATH_MAX];
|
||||||
static int nlines, odd;
|
static int nlines, odd;
|
||||||
static int i;
|
static int i;
|
||||||
|
static size_t ncols;
|
||||||
|
|
||||||
nlines = MIN(LINES - 4, ndents);
|
nlines = MIN(LINES - 4, ndents);
|
||||||
|
|
||||||
|
@ -1201,6 +1207,10 @@ redraw(char *path)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ncols = COLS;
|
||||||
|
if (ncols > PATH_MAX)
|
||||||
|
ncols = PATH_MAX;
|
||||||
|
cwd[ncols - strlen(CWD) - 1] = '\0';
|
||||||
printw(CWD "%s\n\n", cwd);
|
printw(CWD "%s\n\n", cwd);
|
||||||
|
|
||||||
/* Print listing */
|
/* Print listing */
|
||||||
|
|
Loading…
Reference in a new issue