diff options
author | lostd <lostd@2f30.org> | 2014-11-06 13:46:37 +0200 |
---|---|---|
committer | lostd <lostd@2f30.org> | 2014-11-06 13:46:37 +0200 |
commit | 6b7c2506db2844d718be714e88cb631b0c721ad2 (patch) | |
tree | 923eb2c274c06571eb3c950080c0982621ed2014 /noice.c | |
parent | ef3bfef45449a2d660a0ee8880a8888a5aef63fc (diff) | |
download | noice-6b7c2506db2844d718be714e88cb631b0c721ad2.tar.gz |
Expose key bindings in the configuration header
Diffstat (limited to 'noice.c')
-rw-r--r-- | noice.c | 78 |
1 files changed, 24 insertions, 54 deletions
@@ -42,6 +42,25 @@ struct assoc { char *bin; /* Program */ }; +/* Supported actions */ +enum action { + SEL_QUIT = 1, + SEL_BACK, + SEL_GOIN, + SEL_FLTR, + SEL_NEXT, + SEL_PREV, + SEL_PGDN, + SEL_PGUP, + SEL_SH, + SEL_CD, +}; + +struct key { + int sym; /* Key pressed */ + enum action act; /* Action */ +}; + #include "config.h" struct entry { @@ -259,65 +278,16 @@ printprompt(char *str) * 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(void) { - int c; + int c, i; c = getch(); - switch (c) { - case 'q': - return SEL_QUIT; - /* Back */ - case KEY_BACKSPACE: - case KEY_LEFT: - case 'h': - return SEL_BACK; - /* Inside */ - case KEY_ENTER: - case '\r': - case KEY_RIGHT: - case 'l': - return SEL_GOIN; - /* Filter */ - case '/': - case '&': - return SEL_FLTR; - /* Next */ - case 'j': - case KEY_DOWN: - case CONTROL('N'): - return SEL_NEXT; - /* Previous */ - case 'k': - case KEY_UP: - case CONTROL('P'): - return SEL_PREV; - /* Page down */ - case KEY_NPAGE: - case CONTROL('D'): - return SEL_PGDN; - /* Page up */ - case KEY_PPAGE: - case CONTROL('U'): - return SEL_PGUP; - case '!': - return SEL_SH; - case 'c': - return SEL_CD; + + for (i = 0; i < LEN(bindings); i++) { + if (c == bindings[i].sym) + return bindings[i].act; } return 0; |