Expose key bindings in the configuration header

This commit is contained in:
lostd 2014-11-06 13:46:37 +02:00
parent ef3bfef454
commit 6b7c2506db
2 changed files with 59 additions and 54 deletions

View file

@ -10,3 +10,38 @@ struct assoc assocs[] = {
{ "\\.sh$", "sh" },
{ ".*", "less" },
};
struct key bindings[] = {
/* Quit */
{ 'q', SEL_QUIT },
/* Back */
{ KEY_BACKSPACE, SEL_BACK },
{ KEY_LEFT, SEL_BACK },
{ 'h', SEL_BACK },
/* Inside */
{ KEY_ENTER, SEL_GOIN },
{ '\r', SEL_GOIN },
{ KEY_RIGHT, SEL_GOIN },
{ 'l', SEL_GOIN },
/* Filter */
{ '/', SEL_FLTR },
{ '&', SEL_FLTR },
/* Next */
{ 'j', SEL_NEXT },
{ KEY_DOWN, SEL_NEXT },
{ CONTROL('N'), SEL_NEXT },
/* Previous */
{ 'k', SEL_PREV },
{ KEY_UP, SEL_PREV },
{ CONTROL('P'), SEL_PREV },
/* Page down */
{ KEY_NPAGE, SEL_PGDN },
{ CONTROL('D'), SEL_PGDN },
/* Page up */
{ KEY_PPAGE, SEL_PGUP },
{ CONTROL('U'), SEL_PGUP },
/* Shell */
{ '!', SEL_SH },
/* Change dir */
{ 'c', SEL_CD },
};

78
noice.c
View file

@ -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;