mirror of
https://github.com/jarun/nnn.git
synced 2025-01-09 17:39:38 +00:00
Scrolling listing and dirname handling
This commit is contained in:
parent
561caf46db
commit
4fa2a99449
32
noice.c
32
noice.c
|
@ -23,6 +23,7 @@
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
|
||||||
#define LEN(x) (sizeof(x) / sizeof(*(x)))
|
#define LEN(x) (sizeof(x) / sizeof(*(x)))
|
||||||
|
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Layout:
|
* Layout:
|
||||||
|
@ -187,7 +188,7 @@ browse(const char *ipath)
|
||||||
char *path = strdup(ipath);
|
char *path = strdup(ipath);
|
||||||
|
|
||||||
begin:
|
begin:
|
||||||
/* Path is a malloc(3)-ed string */
|
/* Path should be a malloc(3)-ed string at all times */
|
||||||
n = 0;
|
n = 0;
|
||||||
cur = 0;
|
cur = 0;
|
||||||
dents = NULL;
|
dents = NULL;
|
||||||
|
@ -213,6 +214,7 @@ begin:
|
||||||
qsort(dents, n, sizeof(*dents), dentcmp);
|
qsort(dents, n, sizeof(*dents), dentcmp);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
int nlines = MIN(LINES - 4, n);
|
||||||
redraw:
|
redraw:
|
||||||
/* Clean screen */
|
/* Clean screen */
|
||||||
erase();
|
erase();
|
||||||
|
@ -233,10 +235,22 @@ redraw:
|
||||||
path);
|
path);
|
||||||
|
|
||||||
/* Print listing */
|
/* Print listing */
|
||||||
for (i = 0; i < n; i++)
|
if (cur < nlines / 2) {
|
||||||
printw(" %s %s\n",
|
for (i = 0; i < nlines; i++)
|
||||||
i == cur ? ">" : " ",
|
printw(" %s %s\n",
|
||||||
dents[i]->d_name);
|
i == cur ? ">" : " ",
|
||||||
|
dents[i]->d_name);
|
||||||
|
} else if (cur >= n - nlines / 2) {
|
||||||
|
for (i = n - nlines; i < n; i++)
|
||||||
|
printw(" %s %s\n",
|
||||||
|
i == cur ? ">" : " ",
|
||||||
|
dents[i]->d_name);
|
||||||
|
} else {
|
||||||
|
for (i = cur - nlines / 2; i <= cur + nlines / 2; i++)
|
||||||
|
printw(" %s %s\n",
|
||||||
|
i == cur ? ">" : " ",
|
||||||
|
dents[i]->d_name);
|
||||||
|
}
|
||||||
|
|
||||||
nochange:
|
nochange:
|
||||||
ret = nextsel(&cur, n);
|
ret = nextsel(&cur, n);
|
||||||
|
@ -249,7 +263,13 @@ nochange:
|
||||||
if (strncmp(path, "", 1) == 0) {
|
if (strncmp(path, "", 1) == 0) {
|
||||||
goto nochange;
|
goto nochange;
|
||||||
} else {
|
} else {
|
||||||
path = dirname(path);
|
char *dir, *tmp;
|
||||||
|
|
||||||
|
dir = dirname(path);
|
||||||
|
tmp = malloc(strlen(dir) + 1);
|
||||||
|
strncpy(tmp, dir, strlen(dir) + 1);
|
||||||
|
free(path);
|
||||||
|
path = tmp;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue