Process keypress by probable frequency

This commit is contained in:
Arun Prakash Jana 2017-12-13 01:46:50 +05:30
parent 1473416228
commit 1b035d6ffd
No known key found for this signature in database
GPG Key ID: A75979F35C080412
2 changed files with 55 additions and 55 deletions

76
nnn.c
View File

@ -2146,26 +2146,6 @@ nochange:
sel = nextsel(&run, &env, &presel);
switch (sel) {
case SEL_CDQUIT:
{
char *tmpfile = "/tmp/nnn";
tmp = getenv("NNN_TMPFILE");
if (tmp)
tmpfile = tmp;
FILE *fp = fopen(tmpfile, "w");
if (fp) {
fprintf(fp, "cd \"%s\"", path);
fclose(fp);
}
/* Fall through to exit */
} // fallthrough
case SEL_QUIT:
dentfree(dents);
return;
case SEL_BACK:
/* There is no going back */
if (istopdir(path)) {
@ -2264,24 +2244,6 @@ nochange:
printmsg("Unsupported file");
goto nochange;
}
case SEL_FLTR:
presel = filterentries(path);
xstrlcpy(fltr, ifilter, LINE_MAX);
DPRINTF_S(fltr);
/* Save current */
if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, PATH_MAX);
goto nochange;
case SEL_MFLTR:
cfg.filtermode ^= 1;
if (cfg.filtermode)
presel = FILTER;
else
printmsg("navigate-as-you-type off");
goto nochange;
case SEL_SEARCH:
spawn(player, path, "search", NULL, F_NORMAL);
break;
case SEL_NEXT:
if (cur < ndents - 1)
++cur;
@ -2567,6 +2529,24 @@ nochange:
xstrlcpy(mark, path, PATH_MAX);
printmsg(mark);
goto nochange;
case SEL_FLTR:
presel = filterentries(path);
xstrlcpy(fltr, ifilter, LINE_MAX);
DPRINTF_S(fltr);
/* Save current */
if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, PATH_MAX);
goto nochange;
case SEL_MFLTR:
cfg.filtermode ^= 1;
if (cfg.filtermode)
presel = FILTER;
else
printmsg("navigate-as-you-type off");
goto nochange;
case SEL_SEARCH:
spawn(player, path, "search", NULL, F_NORMAL);
break;
case SEL_TOGGLEDOT:
cfg.showhidden ^= 1;
initfilter(cfg.showhidden, &ifilter);
@ -2785,6 +2765,26 @@ nochange:
run = xgetenv(env, run);
spawn(run, dents[cur].name, NULL, path, F_NORMAL);
break;
case SEL_CDQUIT:
{
char *tmpfile = "/tmp/nnn";
tmp = getenv("NNN_TMPFILE");
if (tmp)
tmpfile = tmp;
FILE *fp = fopen(tmpfile, "w");
if (fp) {
fprintf(fp, "cd \"%s\"", path);
fclose(fp);
}
/* Fall through to exit */
} // fallthrough
case SEL_QUIT:
dentfree(dents);
return;
}
/* Screensaver */
if (idletimeout != 0 && idle == idletimeout) {

34
nnn.h
View File

@ -3,13 +3,8 @@
/* Supported actions */
enum action {
SEL_QUIT = 1,
SEL_CDQUIT,
SEL_BACK,
SEL_BACK = 1,
SEL_GOIN,
SEL_FLTR,
SEL_MFLTR,
SEL_SEARCH,
SEL_NEXT,
SEL_PREV,
SEL_PGDN,
@ -23,6 +18,9 @@ enum action {
SEL_CDBM,
SEL_PIN,
SEL_VISIT,
SEL_FLTR,
SEL_MFLTR,
SEL_SEARCH,
SEL_TOGGLEDOT,
SEL_DETAIL,
SEL_STATS,
@ -41,6 +39,8 @@ enum action {
SEL_HELP,
SEL_RUN,
SEL_RUNARG,
SEL_CDQUIT,
SEL_QUIT,
};
/* Associate a pressed key to an action */
@ -62,11 +62,6 @@ static struct assoc assocs[] = {
};
static struct key bindings[] = {
/* Quit */
{ 'q', SEL_QUIT, "", "" },
{ CONTROL('Q'), SEL_QUIT, "", "" },
/* Change dir on quit */
{ 'Q', SEL_CDQUIT, "", "" },
/* Back */
{ KEY_BACKSPACE, SEL_BACK, "", "" },
{ KEY_LEFT, SEL_BACK, "", "" },
@ -77,12 +72,6 @@ static struct key bindings[] = {
{ '\r', SEL_GOIN, "", "" },
{ KEY_RIGHT, SEL_GOIN, "", "" },
{ 'l', SEL_GOIN, "", "" },
/* Filter */
{ '/', SEL_FLTR, "", "" },
/* Toggle filter mode */
{ KEY_IC, SEL_MFLTR, "", "" },
/* Desktop search */
{ CONTROL('_'), SEL_SEARCH, "", "" },
/* Next */
{ 'j', SEL_NEXT, "", "" },
{ KEY_DOWN, SEL_NEXT, "", "" },
@ -121,6 +110,12 @@ static struct key bindings[] = {
{ CONTROL('B'), SEL_PIN, "", "" },
/* Visit marked directory */
{ CONTROL('V'), SEL_VISIT, "", "" },
/* Filter */
{ '/', SEL_FLTR, "", "" },
/* Toggle filter mode */
{ KEY_IC, SEL_MFLTR, "", "" },
/* Desktop search */
{ CONTROL('_'), SEL_SEARCH, "", "" },
/* Toggle hide .dot files */
{ '.', SEL_TOGGLEDOT, "", "" },
/* Detailed listing */
@ -160,4 +155,9 @@ static struct key bindings[] = {
/* Run command with argument */
{ 'e', SEL_RUNARG, "vi", "EDITOR" },
{ 'p', SEL_RUNARG, "less", "PAGER" },
/* Change dir on quit */
{ 'Q', SEL_CDQUIT, "", "" },
/* Quit */
{ 'q', SEL_QUIT, "", "" },
{ CONTROL('Q'), SEL_QUIT, "", "" },
};