Now nextsel() just maps keys to actions

This commit is contained in:
lostd 2014-11-06 10:54:20 +02:00
parent 77565ecdb8
commit ef3bfef454

46
noice.c
View file

@ -256,21 +256,24 @@ printprompt(char *str)
} }
/* /*
* Returns 0 normally * Returns SEL_{QUIT,BACK,GOIN,FLTR,NEXT,PREV,PGDN,PGUP,SH,CD}
* On movement it updates *cur * Returns 0 otherwise
* Returns SEL_{QUIT,BACK,GOIN,FLTR,SH,CD} otherwise
*/ */
enum { enum {
SEL_QUIT = 1, SEL_QUIT = 1,
SEL_BACK, SEL_BACK,
SEL_GOIN, SEL_GOIN,
SEL_FLTR, SEL_FLTR,
SEL_NEXT,
SEL_PREV,
SEL_PGDN,
SEL_PGUP,
SEL_SH, SEL_SH,
SEL_CD, SEL_CD,
}; };
int int
nextsel(int *cur, int max) nextsel(void)
{ {
int c; int c;
@ -297,28 +300,20 @@ nextsel(int *cur, int max)
case 'j': case 'j':
case KEY_DOWN: case KEY_DOWN:
case CONTROL('N'): case CONTROL('N'):
if (*cur < max - 1) return SEL_NEXT;
(*cur)++;
break;
/* Previous */ /* Previous */
case 'k': case 'k':
case KEY_UP: case KEY_UP:
case CONTROL('P'): case CONTROL('P'):
if (*cur > 0) return SEL_PREV;
(*cur)--;
break;
/* Page down */ /* Page down */
case KEY_NPAGE: case KEY_NPAGE:
case CONTROL('D'): case CONTROL('D'):
if (*cur < max -1) return SEL_PGDN;
(*cur) += MIN((LINES - 4) / 2, max - 1 - *cur);
break;
/* Page up */ /* Page up */
case KEY_PPAGE: case KEY_PPAGE:
case CONTROL('U'): case CONTROL('U'):
if (*cur > 0) return SEL_PGUP;
(*cur) -= MIN((LINES - 4) / 2, *cur);
break;
case '!': case '!':
return SEL_SH; return SEL_SH;
case 'c': case 'c':
@ -605,8 +600,7 @@ redraw:
} }
nochange: nochange:
ret = nextsel(&cur, n); switch (nextsel()) {
switch (ret) {
case SEL_QUIT: case SEL_QUIT:
free(path); free(path);
free(filter); free(filter);
@ -705,6 +699,22 @@ nochange:
DPRINTF_S(filter); DPRINTF_S(filter);
cur = 0; cur = 0;
goto out; goto out;
case SEL_NEXT:
if (cur < n - 1)
cur++;
break;
case SEL_PREV:
if (cur > 0)
cur--;
break;
case SEL_PGDN:
if (cur < n - 1)
cur += MIN((LINES - 4) / 2, n - 1 - cur);
break;
case SEL_PGUP:
if (cur > 0)
cur -= MIN((LINES - 4) / 2, cur);
break;
case SEL_SH: case SEL_SH:
exitcurses(); exitcurses();
spawn("/bin/sh", NULL, path); spawn("/bin/sh", NULL, path);