mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Experimental: retain filter in normal mode
This commit is contained in:
parent
c3ff380354
commit
8f3f64b5a6
131
src/nnn.c
131
src/nnn.c
|
@ -676,6 +676,7 @@ static haiku_nm_h haiku_hnd;
|
||||||
#define cleartimeout() timeout(-1)
|
#define cleartimeout() timeout(-1)
|
||||||
#define errexit() printerr(__LINE__)
|
#define errexit() printerr(__LINE__)
|
||||||
#define setdirwatch() (cfg.filtermode ? (presel = FILTER) : (dir_changed = TRUE))
|
#define setdirwatch() (cfg.filtermode ? (presel = FILTER) : (dir_changed = TRUE))
|
||||||
|
#define filterset() (g_ctx[cfg.curctx].c_fltr[1])
|
||||||
/* We don't care about the return value from strcmp() */
|
/* We don't care about the return value from strcmp() */
|
||||||
#define xstrcmp(a, b) (*(a) != *(b) ? -1 : strcmp((a), (b)))
|
#define xstrcmp(a, b) (*(a) != *(b) ? -1 : strcmp((a), (b)))
|
||||||
/* A faster version of xisdigit */
|
/* A faster version of xisdigit */
|
||||||
|
@ -1969,7 +1970,7 @@ finish:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_archive_cmd(char *cmd, char *archive)
|
static void get_archive_cmd(char *cmd, const char *archive)
|
||||||
{
|
{
|
||||||
uchar i = 3;
|
uchar i = 3;
|
||||||
const char *arcmd[] = {"atool -a", "bsdtar -acvf", "zip -r", "tar -acvf"};
|
const char *arcmd[] = {"atool -a", "bsdtar -acvf", "zip -r", "tar -acvf"};
|
||||||
|
@ -2310,7 +2311,7 @@ static int nextsel(int presel)
|
||||||
//DPRINTF_S(keyname(c));
|
//DPRINTF_S(keyname(c));
|
||||||
|
|
||||||
if (c == ERR && presel == MSGWAIT)
|
if (c == ERR && presel == MSGWAIT)
|
||||||
c = (cfg.filtermode) ? FILTER : CONTROL('L');
|
c = (cfg.filtermode || filterset()) ? FILTER : CONTROL('L');
|
||||||
else if (c == FILTER || c == CONTROL('L'))
|
else if (c == FILTER || c == CONTROL('L'))
|
||||||
/* Clear previous filter when manually starting */
|
/* Clear previous filter when manually starting */
|
||||||
clearfilter();
|
clearfilter();
|
||||||
|
@ -2497,6 +2498,9 @@ static int filterentries(char *path, char *lastname)
|
||||||
redraw(path);
|
redraw(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cfg.filtermode)
|
||||||
|
return 0;
|
||||||
|
|
||||||
len = mbstowcs(wln, ln, REGEX_MAX);
|
len = mbstowcs(wln, ln, REGEX_MAX);
|
||||||
} else {
|
} else {
|
||||||
ln[0] = wln[0] = cfg.regex ? RFILTER : FILTER;
|
ln[0] = wln[0] = cfg.regex ? RFILTER : FILTER;
|
||||||
|
@ -2657,11 +2661,6 @@ end:
|
||||||
if (ln[1])
|
if (ln[1])
|
||||||
ln[REGEX_MAX - 1] = ln[1];
|
ln[REGEX_MAX - 1] = ln[1];
|
||||||
|
|
||||||
if (*ch != 27 && *ch != '\t' && *ch != KEY_UP && *ch != KEY_DOWN && *ch != CONTROL('T')) {
|
|
||||||
ln[0] = ln[1] = '\0';
|
|
||||||
move_cursor(cur, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save current */
|
/* Save current */
|
||||||
if (ndents)
|
if (ndents)
|
||||||
copycurname();
|
copycurname();
|
||||||
|
@ -4741,7 +4740,7 @@ static int handle_context_switch(enum action sel, char *newpath)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool set_sort_flags(int r)
|
static int set_sort_flags(int r)
|
||||||
{
|
{
|
||||||
switch (r) {
|
switch (r) {
|
||||||
case 'a': /* Apparent du */
|
case 'a': /* Apparent du */
|
||||||
|
@ -4770,7 +4769,6 @@ static bool set_sort_flags(int r)
|
||||||
cfg.sizeorder = 0;
|
cfg.sizeorder = 0;
|
||||||
cfg.extnorder = 0;
|
cfg.extnorder = 0;
|
||||||
entrycmpfn = &entrycmp;
|
entrycmpfn = &entrycmp;
|
||||||
clearfilter(); /* Reload directory */
|
|
||||||
endselection(); /* We are going to reload dir */
|
endselection(); /* We are going to reload dir */
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -4813,10 +4811,10 @@ static bool set_sort_flags(int r)
|
||||||
namecmpfn = (namecmpfn == &xstrverscasecmp) ? &xstricmp : &xstrverscasecmp;
|
namecmpfn = (namecmpfn == &xstrverscasecmp) ? &xstricmp : &xstrverscasecmp;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool set_time_type(int *presel)
|
static bool set_time_type(int *presel)
|
||||||
|
@ -4974,6 +4972,8 @@ static void redraw(char *path)
|
||||||
xlines = LINES;
|
xlines = LINES;
|
||||||
xcols = COLS;
|
xcols = COLS;
|
||||||
|
|
||||||
|
DPRINTF_S(__FUNCTION__);
|
||||||
|
|
||||||
int ncols = (xcols <= PATH_MAX) ? xcols : PATH_MAX;
|
int ncols = (xcols <= PATH_MAX) ? xcols : PATH_MAX;
|
||||||
int onscreen = xlines - 4;
|
int onscreen = xlines - 4;
|
||||||
int i;
|
int i;
|
||||||
|
@ -5342,8 +5342,13 @@ nochange:
|
||||||
> DOUBLECLICK_INTERVAL_NS)
|
> DOUBLECLICK_INTERVAL_NS)
|
||||||
break;
|
break;
|
||||||
mousetimings[currentmouse].tv_sec = 0;
|
mousetimings[currentmouse].tv_sec = 0;
|
||||||
} else
|
} else {
|
||||||
|
if (cfg.filtermode || filterset())
|
||||||
|
presel = FILTER;
|
||||||
|
if (ndents)
|
||||||
|
copycurname();
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case SEL_NAV_IN: // fallthrough
|
case SEL_NAV_IN: // fallthrough
|
||||||
|
@ -5445,6 +5450,10 @@ nochange:
|
||||||
mkpath(path, dents[cur].name, newpath);
|
mkpath(path, dents[cur].name, newpath);
|
||||||
handle_archive(newpath, path, r);
|
handle_archive(newpath, path, r);
|
||||||
copycurname();
|
copycurname();
|
||||||
|
if (r == 'l') {
|
||||||
|
statusbar(path);
|
||||||
|
goto nochange;
|
||||||
|
}
|
||||||
goto begin;
|
goto begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5478,7 +5487,6 @@ nochange:
|
||||||
/* Move cursor to the next entry if not the last entry */
|
/* Move cursor to the next entry if not the last entry */
|
||||||
if ((g_states & STATE_AUTONEXT) && cur != ndents - 1)
|
if ((g_states & STATE_AUTONEXT) && cur != ndents - 1)
|
||||||
move_cursor((cur + 1) % ndents, 0);
|
move_cursor((cur + 1) % ndents, 0);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -5653,24 +5661,23 @@ nochange:
|
||||||
cfg.blkorder = 0;
|
cfg.blkorder = 0;
|
||||||
continue;
|
continue;
|
||||||
default: /* SEL_SORT */
|
default: /* SEL_SORT */
|
||||||
if (!set_sort_flags(get_input(messages[MSG_ORDER]))) {
|
r = set_sort_flags(get_input(messages[MSG_ORDER]));
|
||||||
|
if (!r) {
|
||||||
printwait(messages[MSG_INVALID_KEY], &presel);
|
printwait(messages[MSG_INVALID_KEY], &presel);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cfg.blkorder && cfg.filtermode)
|
|
||||||
presel = FILTER;
|
|
||||||
|
|
||||||
/* Save current */
|
/* Save current */
|
||||||
if (ndents)
|
if (ndents)
|
||||||
copycurname();
|
copycurname();
|
||||||
|
|
||||||
/* If there's no filter, reload the directory */
|
if (cfg.filtermode || filterset())
|
||||||
if (!g_ctx[cfg.curctx].c_fltr[1])
|
presel = FILTER;
|
||||||
|
|
||||||
|
if (r == 'd' || r == 'a')
|
||||||
goto begin;
|
goto begin;
|
||||||
|
|
||||||
presel = FILTER; /* If there's a filter, apply it */
|
|
||||||
break;
|
break;
|
||||||
case SEL_STATS: // fallthrough
|
case SEL_STATS: // fallthrough
|
||||||
case SEL_CHMODX:
|
case SEL_CHMODX:
|
||||||
|
@ -5692,6 +5699,7 @@ nochange:
|
||||||
case SEL_REDRAW: // fallthrough
|
case SEL_REDRAW: // fallthrough
|
||||||
case SEL_RENAMEMUL: // fallthrough
|
case SEL_RENAMEMUL: // fallthrough
|
||||||
case SEL_HELP: // fallthrough
|
case SEL_HELP: // fallthrough
|
||||||
|
case SEL_AUTONEXT: // fallthrough
|
||||||
case SEL_EDIT: // fallthrough
|
case SEL_EDIT: // fallthrough
|
||||||
case SEL_LOCK:
|
case SEL_LOCK:
|
||||||
{
|
{
|
||||||
|
@ -5718,10 +5726,15 @@ nochange:
|
||||||
refresh = TRUE;
|
refresh = TRUE;
|
||||||
break;
|
break;
|
||||||
case SEL_HELP:
|
case SEL_HELP:
|
||||||
show_help(path);
|
show_help(path); // fallthrough
|
||||||
|
case SEL_AUTONEXT:
|
||||||
|
if (sel == SEL_AUTONEXT)
|
||||||
|
g_states ^= STATE_AUTONEXT;
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode)
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
continue;
|
if (ndents)
|
||||||
|
copycurname();
|
||||||
|
goto nochange;
|
||||||
case SEL_EDIT:
|
case SEL_EDIT:
|
||||||
spawn(editor, dents[cur].name, NULL, path, F_CLI);
|
spawn(editor, dents[cur].name, NULL, path, F_CLI);
|
||||||
continue;
|
continue;
|
||||||
|
@ -5733,7 +5746,7 @@ nochange:
|
||||||
/* In case of successful operation, reload contents */
|
/* In case of successful operation, reload contents */
|
||||||
|
|
||||||
/* Continue in navigate-as-you-type mode, if enabled */
|
/* Continue in navigate-as-you-type mode, if enabled */
|
||||||
if (cfg.filtermode && !refresh)
|
if ((cfg.filtermode || filterset()) && !refresh)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Save current */
|
/* Save current */
|
||||||
|
@ -5874,13 +5887,15 @@ nochange:
|
||||||
mkpath(tmp, dents[cur].name, newpath);
|
mkpath(tmp, dents[cur].name, newpath);
|
||||||
xrm(newpath);
|
xrm(newpath);
|
||||||
|
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode || filterset())
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
|
|
||||||
if (access(newpath, F_OK) == 0) { /* File not removed */
|
if (access(newpath, F_OK) == 0) { /* File not removed */
|
||||||
copycurname();
|
copycurname();
|
||||||
|
if (!cfg.filtermode)
|
||||||
|
statusbar(path);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
} else if (cur) {
|
} else if (ndents) {
|
||||||
cur += (cur != (ndents - 1)) ? 1 : -1;
|
cur += (cur != (ndents - 1)) ? 1 : -1;
|
||||||
copycurname();
|
copycurname();
|
||||||
} else
|
} else
|
||||||
|
@ -5998,25 +6013,30 @@ nochange:
|
||||||
(r == 's') ? archive_selection(newpath, tmp, path)
|
(r == 's') ? archive_selection(newpath, tmp, path)
|
||||||
: spawn(newpath, tmp, dents[cur].name,
|
: spawn(newpath, tmp, dents[cur].name,
|
||||||
path, F_NORMAL | F_MULTI);
|
path, F_NORMAL | F_MULTI);
|
||||||
// fallthrough
|
|
||||||
|
mkpath(path, tmp, newpath);
|
||||||
|
if (access(newpath, F_OK) == 0) { /* File created */
|
||||||
|
xstrlcpy(lastname, tmp, NAME_MAX + 1);
|
||||||
|
clearfilter(); /* Archive name may not match */
|
||||||
|
} else {
|
||||||
|
if (cfg.filtermode)
|
||||||
|
presel = FILTER;
|
||||||
|
copycurname();
|
||||||
|
}
|
||||||
|
goto begin;
|
||||||
case SEL_OPENWITH:
|
case SEL_OPENWITH:
|
||||||
if (sel == SEL_OPENWITH) {
|
/* Confirm if app is CLI or GUI */
|
||||||
/* Confirm if app is CLI or GUI */
|
r = get_input(messages[MSG_CLI_MODE]);
|
||||||
r = get_input(messages[MSG_CLI_MODE]);
|
r = (r == 'c' ? F_CLI :
|
||||||
r = (r == 'c' ? F_CLI :
|
(r == 'g' ? F_NOWAIT | F_NOTRACE | F_MULTI : 0));
|
||||||
(r == 'g' ? F_NOWAIT | F_NOTRACE | F_MULTI : 0));
|
if (r) {
|
||||||
if (!r) {
|
|
||||||
cfg.filtermode ? presel = FILTER : statusbar(path);
|
|
||||||
goto nochange;
|
|
||||||
}
|
|
||||||
mkpath(path, dents[cur].name, newpath);
|
mkpath(path, dents[cur].name, newpath);
|
||||||
spawn(tmp, newpath, NULL, path, r);
|
spawn(tmp, newpath, NULL, path, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.filtermode)
|
cfg.filtermode ? presel = FILTER : statusbar(path);
|
||||||
presel = FILTER;
|
|
||||||
copycurname();
|
copycurname();
|
||||||
goto begin;
|
goto nochange;
|
||||||
case SEL_RENAME:
|
case SEL_RENAME:
|
||||||
/* Skip renaming to same name */
|
/* Skip renaming to same name */
|
||||||
if (strcmp(tmp, dents[cur].name) == 0) {
|
if (strcmp(tmp, dents[cur].name) == 0) {
|
||||||
|
@ -6081,7 +6101,6 @@ nochange:
|
||||||
mkpath(path, tmp, newpath);
|
mkpath(path, tmp, newpath);
|
||||||
ret = xmktree(newpath, TRUE);
|
ret = xmktree(newpath, TRUE);
|
||||||
} else if (r == 's' || r == 'h') {
|
} else if (r == 's' || r == 'h') {
|
||||||
|
|
||||||
if (tmp[0] == '@' && tmp[1] == '\0')
|
if (tmp[0] == '@' && tmp[1] == '\0')
|
||||||
tmp[0] = '\0';
|
tmp[0] = '\0';
|
||||||
ret = xlink(tmp, path, (ndents ? dents[cur].name : NULL),
|
ret = xlink(tmp, path, (ndents ? dents[cur].name : NULL),
|
||||||
|
@ -6101,6 +6120,7 @@ nochange:
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
copycurname();
|
copycurname();
|
||||||
}
|
}
|
||||||
|
clearfilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
goto begin;
|
goto begin;
|
||||||
|
@ -6192,8 +6212,11 @@ nochange:
|
||||||
|
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode)
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
|
if (ndents)
|
||||||
|
copycurname();
|
||||||
goto nochange;
|
goto nochange;
|
||||||
default: /* SEL_RUNCMD */
|
default: /* SEL_RUNCMD */
|
||||||
|
r = TRUE;
|
||||||
#ifndef NORL
|
#ifndef NORL
|
||||||
if (cfg.picker) {
|
if (cfg.picker) {
|
||||||
#endif
|
#endif
|
||||||
|
@ -6208,11 +6231,8 @@ nochange:
|
||||||
#endif
|
#endif
|
||||||
if (tmp && *tmp) // NOLINT
|
if (tmp && *tmp) // NOLINT
|
||||||
prompt_run(tmp, (ndents ? dents[cur].name : ""), path);
|
prompt_run(tmp, (ndents ? dents[cur].name : ""), path);
|
||||||
else {
|
else
|
||||||
if (cfg.filtermode)
|
r = FALSE;
|
||||||
presel = FILTER;
|
|
||||||
goto nochange;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Continue in navigate-as-you-type mode, if enabled */
|
/* Continue in navigate-as-you-type mode, if enabled */
|
||||||
|
@ -6222,6 +6242,10 @@ nochange:
|
||||||
/* Save current */
|
/* Save current */
|
||||||
if (ndents)
|
if (ndents)
|
||||||
copycurname();
|
copycurname();
|
||||||
|
|
||||||
|
if (!r)
|
||||||
|
goto nochange;
|
||||||
|
|
||||||
/* Repopulate as directory content may have changed */
|
/* Repopulate as directory content may have changed */
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_REMOTE:
|
case SEL_REMOTE:
|
||||||
|
@ -6256,11 +6280,6 @@ nochange:
|
||||||
|
|
||||||
statusbar(path);
|
statusbar(path);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
case SEL_AUTONEXT:
|
|
||||||
g_states ^= STATE_AUTONEXT;
|
|
||||||
if (cfg.filtermode)
|
|
||||||
presel = FILTER;
|
|
||||||
goto nochange;
|
|
||||||
case SEL_QUITCTX: // fallthrough
|
case SEL_QUITCTX: // fallthrough
|
||||||
case SEL_QUITCD: // fallthrough
|
case SEL_QUITCD: // fallthrough
|
||||||
case SEL_QUIT:
|
case SEL_QUIT:
|
||||||
|
@ -6323,17 +6342,21 @@ nochange:
|
||||||
goto nochange;
|
goto nochange;
|
||||||
goto begin;
|
goto begin;
|
||||||
default:
|
default:
|
||||||
if (xlines != LINES || xcols != COLS)
|
r = FALSE;
|
||||||
|
if (xlines != LINES || xcols != COLS) {
|
||||||
setdirwatch(); /* Terminal resized */
|
setdirwatch(); /* Terminal resized */
|
||||||
else if (idletimeout && idle == idletimeout)
|
r = TRUE;
|
||||||
|
} else if (idletimeout && idle == idletimeout)
|
||||||
lock_terminal(); /* Locker */
|
lock_terminal(); /* Locker */
|
||||||
else
|
|
||||||
goto nochange;
|
|
||||||
|
|
||||||
idle = 0;
|
idle = 0;
|
||||||
if (ndents)
|
if (ndents)
|
||||||
copycurname();
|
copycurname();
|
||||||
goto begin;
|
|
||||||
|
if (r)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
goto nochange;
|
||||||
} /* switch (sel) */
|
} /* switch (sel) */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,7 @@ enum action {
|
||||||
SEL_REMOTE,
|
SEL_REMOTE,
|
||||||
SEL_UMOUNT,
|
SEL_UMOUNT,
|
||||||
SEL_HELP,
|
SEL_HELP,
|
||||||
|
SEL_AUTONEXT,
|
||||||
SEL_EDIT,
|
SEL_EDIT,
|
||||||
SEL_PLUGIN,
|
SEL_PLUGIN,
|
||||||
SEL_SHELL,
|
SEL_SHELL,
|
||||||
|
@ -91,7 +92,6 @@ enum action {
|
||||||
SEL_RUNCMD,
|
SEL_RUNCMD,
|
||||||
SEL_LOCK,
|
SEL_LOCK,
|
||||||
SEL_SESSIONS,
|
SEL_SESSIONS,
|
||||||
SEL_AUTONEXT,
|
|
||||||
SEL_QUITCTX,
|
SEL_QUITCTX,
|
||||||
SEL_QUITCD,
|
SEL_QUITCD,
|
||||||
SEL_QUIT,
|
SEL_QUIT,
|
||||||
|
@ -223,6 +223,8 @@ static struct key bindings[] = {
|
||||||
{ 'u', SEL_UMOUNT },
|
{ 'u', SEL_UMOUNT },
|
||||||
/* Show help */
|
/* Show help */
|
||||||
{ '?', SEL_HELP },
|
{ '?', SEL_HELP },
|
||||||
|
/* Quit a context */
|
||||||
|
{ '+', SEL_AUTONEXT },
|
||||||
/* Edit in EDITOR */
|
/* Edit in EDITOR */
|
||||||
{ 'e', SEL_EDIT },
|
{ 'e', SEL_EDIT },
|
||||||
/* Run a plugin */
|
/* Run a plugin */
|
||||||
|
@ -240,8 +242,6 @@ static struct key bindings[] = {
|
||||||
/* Manage sessions */
|
/* Manage sessions */
|
||||||
{ 's', SEL_SESSIONS },
|
{ 's', SEL_SESSIONS },
|
||||||
/* Quit a context */
|
/* Quit a context */
|
||||||
{ '+', SEL_AUTONEXT },
|
|
||||||
/* Quit a context */
|
|
||||||
{ 'q', SEL_QUITCTX },
|
{ 'q', SEL_QUITCTX },
|
||||||
/* Change dir on quit */
|
/* Change dir on quit */
|
||||||
{ CONTROL('G'), SEL_QUITCD },
|
{ CONTROL('G'), SEL_QUITCD },
|
||||||
|
@ -249,7 +249,9 @@ static struct key bindings[] = {
|
||||||
{ CONTROL('Q'), SEL_QUIT },
|
{ CONTROL('Q'), SEL_QUIT },
|
||||||
/* Quit with an error code */
|
/* Quit with an error code */
|
||||||
{ 'Q', SEL_QUITFAIL },
|
{ 'Q', SEL_QUITFAIL },
|
||||||
|
/* Export list */
|
||||||
{ '>', SEL_EXPORT },
|
{ '>', SEL_EXPORT },
|
||||||
|
/* Set time type */
|
||||||
{ 'T', SEL_TIMETYPE },
|
{ 'T', SEL_TIMETYPE },
|
||||||
#ifndef NOMOUSE
|
#ifndef NOMOUSE
|
||||||
{ KEY_MOUSE, SEL_CLICK },
|
{ KEY_MOUSE, SEL_CLICK },
|
||||||
|
|
Loading…
Reference in a new issue