aboutsummaryrefslogtreecommitdiffstats
path: root/noice.c
diff options
context:
space:
mode:
authorlostd <lostd@2f30.org>2014-11-06 10:54:20 +0200
committerlostd <lostd@2f30.org>2014-11-06 10:54:20 +0200
commitef3bfef45449a2d660a0ee8880a8888a5aef63fc (patch)
tree6f2fbc22f77177f7f4f4844a303742f8f848eb2a /noice.c
parent77565ecdb87d9771bcd929b222c2af2345a37e26 (diff)
downloadnoice-ef3bfef45449a2d660a0ee8880a8888a5aef63fc.tar.gz
Now nextsel() just maps keys to actions
Diffstat (limited to 'noice.c')
-rw-r--r--noice.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/noice.c b/noice.c
index 89da676..3bbdb46 100644
--- a/noice.c
+++ b/noice.c
@@ -256,21 +256,24 @@ printprompt(char *str)
}
/*
- * Returns 0 normally
- * On movement it updates *cur
- * Returns SEL_{QUIT,BACK,GOIN,FLTR,SH,CD} otherwise
+ * Returns SEL_{QUIT,BACK,GOIN,FLTR,NEXT,PREV,PGDN,PGUP,SH,CD}
+ * Returns 0 otherwise
*/
enum {
SEL_QUIT = 1,
SEL_BACK,
SEL_GOIN,
SEL_FLTR,
+ SEL_NEXT,
+ SEL_PREV,
+ SEL_PGDN,
+ SEL_PGUP,
SEL_SH,
SEL_CD,
};
int
-nextsel(int *cur, int max)
+nextsel(void)
{
int c;
@@ -297,28 +300,20 @@ nextsel(int *cur, int max)
case 'j':
case KEY_DOWN:
case CONTROL('N'):
- if (*cur < max - 1)
- (*cur)++;
- break;
+ return SEL_NEXT;
/* Previous */
case 'k':
case KEY_UP:
case CONTROL('P'):
- if (*cur > 0)
- (*cur)--;
- break;
+ return SEL_PREV;
/* Page down */
case KEY_NPAGE:
case CONTROL('D'):
- if (*cur < max -1)
- (*cur) += MIN((LINES - 4) / 2, max - 1 - *cur);
- break;
+ return SEL_PGDN;
/* Page up */
case KEY_PPAGE:
case CONTROL('U'):
- if (*cur > 0)
- (*cur) -= MIN((LINES - 4) / 2, *cur);
- break;
+ return SEL_PGUP;
case '!':
return SEL_SH;
case 'c':
@@ -605,8 +600,7 @@ redraw:
}
nochange:
- ret = nextsel(&cur, n);
- switch (ret) {
+ switch (nextsel()) {
case SEL_QUIT:
free(path);
free(filter);
@@ -705,6 +699,22 @@ nochange:
DPRINTF_S(filter);
cur = 0;
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:
exitcurses();
spawn("/bin/sh", NULL, path);
Un proyecto texto-plano.xyz