mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Add pushhist(), pophist() and forgethist()
This commit is contained in:
parent
1183a9428f
commit
aedec0ddf3
76
noice.c
76
noice.c
|
@ -482,6 +482,47 @@ dentfree(struct entry *dents, int n)
|
||||||
free(dents);
|
free(dents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pushhist(int pos)
|
||||||
|
{
|
||||||
|
struct history *hist;
|
||||||
|
|
||||||
|
hist = xmalloc(sizeof(*hist));
|
||||||
|
hist->pos = pos;
|
||||||
|
SLIST_INSERT_HEAD(&histhead, hist, entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
pophist(void)
|
||||||
|
{
|
||||||
|
struct history *hist;
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
/* Recall history */
|
||||||
|
hist = SLIST_FIRST(&histhead);
|
||||||
|
if (hist != NULL) {
|
||||||
|
pos = hist->pos;
|
||||||
|
SLIST_REMOVE_HEAD(&histhead, entry);
|
||||||
|
free(hist);
|
||||||
|
} else {
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
forgethist(void)
|
||||||
|
{
|
||||||
|
struct history *hist;
|
||||||
|
|
||||||
|
while (!SLIST_EMPTY(&histhead)) {
|
||||||
|
hist = SLIST_FIRST(&histhead);
|
||||||
|
SLIST_REMOVE_HEAD(&histhead, entry);
|
||||||
|
free(hist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
browse(const char *ipath, const char *ifilter)
|
browse(const char *ipath, const char *ifilter)
|
||||||
{
|
{
|
||||||
|
@ -530,7 +571,6 @@ begin:
|
||||||
char *dir;
|
char *dir;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
regex_t re;
|
regex_t re;
|
||||||
struct history *hist;
|
|
||||||
|
|
||||||
redraw:
|
redraw:
|
||||||
nlines = MIN(LINES - 4, n);
|
nlines = MIN(LINES - 4, n);
|
||||||
|
@ -569,11 +609,7 @@ nochange:
|
||||||
free(path);
|
free(path);
|
||||||
free(filter);
|
free(filter);
|
||||||
/* Forget history */
|
/* Forget history */
|
||||||
while (!SLIST_EMPTY(&histhead)) {
|
forgethist();
|
||||||
hist = SLIST_FIRST(&histhead);
|
|
||||||
SLIST_REMOVE_HEAD(&histhead, entry);
|
|
||||||
free(hist);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
case SEL_BACK:
|
case SEL_BACK:
|
||||||
/* There is no going back */
|
/* There is no going back */
|
||||||
|
@ -582,18 +618,11 @@ nochange:
|
||||||
dir = xdirname(path);
|
dir = xdirname(path);
|
||||||
free(path);
|
free(path);
|
||||||
path = dir;
|
path = dir;
|
||||||
|
/* Reset filter */
|
||||||
free(filter);
|
free(filter);
|
||||||
filter = xstrdup(ifilter); /* Reset filter */
|
filter = xstrdup(ifilter);
|
||||||
/* Recall history */
|
/* Recall history */
|
||||||
hist = SLIST_FIRST(&histhead);
|
cur = pophist();
|
||||||
if (hist != NULL) {
|
|
||||||
cur = hist->pos;
|
|
||||||
DPRINTF_D(hist->pos);
|
|
||||||
SLIST_REMOVE_HEAD(&histhead, entry);
|
|
||||||
free(hist);
|
|
||||||
} else {
|
|
||||||
cur = 0;
|
|
||||||
}
|
|
||||||
goto out;
|
goto out;
|
||||||
case SEL_GOIN:
|
case SEL_GOIN:
|
||||||
/* Cannot descend in empty directories */
|
/* Cannot descend in empty directories */
|
||||||
|
@ -615,12 +644,11 @@ nochange:
|
||||||
case S_IFDIR:
|
case S_IFDIR:
|
||||||
free(path);
|
free(path);
|
||||||
path = xrealpath(name);
|
path = xrealpath(name);
|
||||||
|
/* Reset filter */
|
||||||
free(filter);
|
free(filter);
|
||||||
filter = xstrdup(ifilter); /* Reset filter */
|
filter = xstrdup(ifilter);
|
||||||
/* Save history */
|
/* Remember history */
|
||||||
hist = xmalloc(sizeof(struct history));
|
pushhist(cur);
|
||||||
hist->pos = cur;
|
|
||||||
SLIST_INSERT_HEAD(&histhead, hist, entry);
|
|
||||||
cur = 0;
|
cur = 0;
|
||||||
goto out;
|
goto out;
|
||||||
case S_IFREG:
|
case S_IFREG:
|
||||||
|
@ -679,11 +707,7 @@ nochange:
|
||||||
free(filter);
|
free(filter);
|
||||||
filter = xstrdup(ifilter); /* Reset filter */
|
filter = xstrdup(ifilter); /* Reset filter */
|
||||||
/* Forget history */
|
/* Forget history */
|
||||||
while (!SLIST_EMPTY(&histhead)) {
|
forgethist();
|
||||||
hist = SLIST_FIRST(&histhead);
|
|
||||||
SLIST_REMOVE_HEAD(&histhead, entry);
|
|
||||||
free(hist);
|
|
||||||
}
|
|
||||||
DPRINTF_S(path);
|
DPRINTF_S(path);
|
||||||
cur = 0;
|
cur = 0;
|
||||||
goto out;
|
goto out;
|
||||||
|
|
Loading…
Reference in a new issue