added support for arrow and page keys - iomenu - interactive terminal-based selection menu
(HTM) git clone git://bitreich.org/iomenu git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/iomenu
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
(DIR) commit 2425ac3f4cb13eef4db1e4e4d66feede9bf3ab84
(DIR) parent 422bb3cf75123ac36aed39c370de89dfbe55dd78
(HTM) Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date: Mon, 21 Aug 2017 15:28:29 +0200
added support for arrow and page keys
Diffstat:
M README | 4 ++--
M iomenu.1 | 4 ++--
M iomenu.c | 38 ++++++++++++++++++++++++++-----
3 files changed, 36 insertions(+), 10 deletions(-)
---
(DIR) 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
(DIR) 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
(DIR) 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;