iomenu

interactive text selection menu
Log | Files | Refs | README | LICENSE

commit 2425ac3f4cb13eef4db1e4e4d66feede9bf3ab84
parent 422bb3cf75123ac36aed39c370de89dfbe55dd78
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Mon, 21 Aug 2017 15:28:29 +0200

added support for arrow and page keys

Diffstat:
MREADME | 4++--
Miomenu.1 | 4++--
Miomenu.c | 38++++++++++++++++++++++++++++++++------
3 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/README b/README @@ -26,10 +26,10 @@ DESCRIPTION An active selection is highlighted, and can be controlled with keybindings. - Ctrl + p, Ctrl + n + Up, Down, Ctrl + p, Ctrl + n Move selection to the previous/next item. - Ctrl + v Ns, Alt + v + PageUp, PageDown, Alt + v, Ctrl + v Move one page up or down. Ctrl + m, Ctrl + j, Enter diff --git a/iomenu.1 b/iomenu.1 @@ -59,10 +59,10 @@ printed. An active selection is highlighted, and can be controlled with keybindings. .Bl -tag -width XXXXXXXXXXXXXXX . -.It Ic Ctrl + p Ns , Ic Ctrl + n +.It Ic Up Ns , Ic Down Ns , Ic Ctrl + p Ns , Ic Ctrl + n Move selection to the previous/next item. . -.It Ic Ctrl + v Ns, Ic Alt + v +.It Ic PageUp Ns , Ic PageDown Ns , Ic Alt + v Ns , Ic Ctrl + v Move one page up or down. . .It Ic Ctrl + m Ns , Ic Ctrl + j Ns , Ic Enter diff --git a/iomenu.c b/iomenu.c @@ -16,6 +16,8 @@ #define ALT(char) (char + 0x80) #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) +enum { KEY_UP = 0x81, KEY_DOWN, PG_UP, PG_DOWN }; + static struct winsize ws; static struct termios termios; static int ttyfd; @@ -339,22 +341,26 @@ top: filter(); break; - case CONTROL('N'): - move(+1); - break; - + case KEY_UP: case CONTROL('P'): move(-1); break; - case CONTROL('V'): - movepg(+1); + case KEY_DOWN: + case CONTROL('N'): + move(+1); break; + case PG_UP: case ALT('v'): movepg(-1); break; + case PG_DOWN: + case CONTROL('V'): + movepg(+1); + break; + case CONTROL('I'): /* tab */ if (linec > 0) strcpy(input, matchv[current]); @@ -366,6 +372,26 @@ top: printselection(); return EXIT_SUCCESS; + case ALT('['): + switch (fgetc(stdin)) { + case 'A': + key = KEY_UP; + goto top; + case 'B': + key = KEY_DOWN; + goto top; + case '5': + if (fgetc(stdin) == '~') { + key = PG_UP; + goto top; + } + case '6': + if (fgetc(stdin) == '~') { + key = PG_DOWN; + goto top; + } + } + case 033: /* escape / alt */ key = ALT(fgetc(stdin)); goto top;