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); sel = nextsel(&run, &env, &presel);
switch (sel) { 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: case SEL_BACK:
/* There is no going back */ /* There is no going back */
if (istopdir(path)) { if (istopdir(path)) {
@ -2264,24 +2244,6 @@ nochange:
printmsg("Unsupported file"); printmsg("Unsupported file");
goto nochange; 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: case SEL_NEXT:
if (cur < ndents - 1) if (cur < ndents - 1)
++cur; ++cur;
@ -2567,6 +2529,24 @@ nochange:
xstrlcpy(mark, path, PATH_MAX); xstrlcpy(mark, path, PATH_MAX);
printmsg(mark); printmsg(mark);
goto nochange; 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: case SEL_TOGGLEDOT:
cfg.showhidden ^= 1; cfg.showhidden ^= 1;
initfilter(cfg.showhidden, &ifilter); initfilter(cfg.showhidden, &ifilter);
@ -2785,6 +2765,26 @@ nochange:
run = xgetenv(env, run); run = xgetenv(env, run);
spawn(run, dents[cur].name, NULL, path, F_NORMAL); spawn(run, dents[cur].name, NULL, path, F_NORMAL);
break; 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 */ /* Screensaver */
if (idletimeout != 0 && idle == idletimeout) { if (idletimeout != 0 && idle == idletimeout) {

34
nnn.h
View file

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