support vi keys (:ijkl)
authorLaurent Mazet <mazet@softndesign.org>
Wed, 8 May 2024 21:55:23 +0000 (23:55 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Wed, 8 May 2024 21:55:23 +0000 (23:55 +0200)
cmore.c
tui.c

diff --git a/cmore.c b/cmore.c
index 9b08436e1998da67c86d16c220739edb22a12c8f..33fb2768ffc341845a9af5f9eb5a91a68a0e7dc9 100644 (file)
--- a/cmore.c
+++ b/cmore.c
@@ -66,10 +66,12 @@ void display (char **lines, int xmax, int ymax)
         VERBOSE (DEBUG, fprintf (stdout, "key pressed: 0x%04x (%c)\n", key, (key >= ' ') && (key < 256) ? key : '.'));
         switch (key) {
         case KEY_ESC:
+        case ':':
 #ifndef __PDCURSES__
             key = waitforkey ();
             switch (key) {
             case KEY_ESC:
+            case ':':
                 DoExit ();
                 /* fallthrough */
             case 'f':
@@ -276,5 +278,7 @@ int main (int argc, char *argv[])
 /* test: (sleep 1; echo -n kkkkk; sleep 1; echo -n i; sleep 1; echo -n q) | cmore.exe -c 'ip addr' */
 /* test: (sleep 1; echo -n q) | cmore.exe -c 'echo -n a; for i in $(seq 1 '$(( $COLUMNS*($LINES-4)-2 ))'); do echo -n .; done; echo -n z' -v 5 | grep -q 'last line too long' */
 /* test: (sleep 1; echo -n q) | cmore.exe -c 'echo -n a; for i in $(seq 1 '$(( $COLUMNS*($LINES-4)-3 ))'); do echo -n .; done; echo -n z' -v 5 | grep -q 'last line too long'; test $? -eq 1 */
+/* test: (sleep 1; echo :f; sleep 1; echo k) | cmore.exe -c 'ip addr' */
+/* test: (sleep 1; echo :fj; sleep 1; echo) | cmore.exe -c 'ip addr' */
 
 /* vim: set ts=4 sw=4 et: */
diff --git a/tui.c b/tui.c
index c83211cead8cab9f7b70faf31b87ff78b5318973..231f28372efa6deb0a8c8c7adf401ac59435cbc7 100644 (file)
--- a/tui.c
+++ b/tui.c
@@ -283,6 +283,7 @@ void mainmenu(menu *mp)
         switch (c = (key != ERR ? key : waitforkey()))
         {
         case KEY_DOWN:
+        case 'k':
         case '\n':              /* menu item selected */
             touchwin(wbody);
             wrefresh(wbody);
@@ -295,11 +296,13 @@ void mainmenu(menu *mp)
             switch (key)
             {
             case KEY_LEFT:
+            case 'j':
                 cur = (cur + nitems - 1) % nitems;
                 key = '\n';
                 break;
 
             case KEY_RIGHT:
+            case 'l':
                 cur = (cur + 1) % nitems;
                 key = '\n';
                 break;
@@ -313,14 +316,17 @@ void mainmenu(menu *mp)
             break;
 
         case KEY_LEFT:
+        case 'j':
             cur = (cur + nitems - 1) % nitems;
             break;
 
         case KEY_RIGHT:
+        case 'l':
             cur = (cur + 1) % nitems;
             break;
 
         case KEY_ESC:
+        case ':':
             mainhelp();
             break;
 
@@ -503,19 +509,24 @@ void domenu(menu *mp)
             break;
 
         case KEY_UP:
+        case 'k':
             cur = (cur + nitems - 1) % nitems;
             key = ERR;
             break;
 
         case KEY_DOWN:
+        case 'i':
             cur = (cur + 1) % nitems;
             key = ERR;
             break;
 
         case KEY_ESC:
+        case ':':
         case KEY_LEFT:
+        case 'j':
         case KEY_RIGHT:
-            if (key == KEY_ESC)
+        case 'l':
+            if ((key == KEY_ESC) || (key == ':'))
                 key = ERR;  /* return to prev submenu */
 
             stop = TRUE;
@@ -663,22 +674,27 @@ int weditstr(WINDOW *win, char *buf, int field)
             break;
 
         case KEY_ESC:
+        case ':':
             strcpy(buf, org);   /* restore original */
             stop = TRUE;
             break;
 
         case '\n':
         case KEY_UP:
+        case 'i':
         case KEY_DOWN:
+        case 'k':
             stop = TRUE;
             break;
 
         case KEY_LEFT:
+        case 'j':
             if (bp > buf)
                 bp--;
             break;
 
         case KEY_RIGHT:
+        case 'l':
             defdisp = FALSE;
             if (bp - buf < (int)strlen(buf))
                 bp++;
@@ -802,16 +818,19 @@ int getstrings(char *desc[], char *buf[], int field)
         switch (c = mvweditstr(winput, i+1, mmax+3, buf[i], field))
         {
         case KEY_ESC:
+        case ':':
             stop = TRUE;
             break;
 
         case KEY_UP:
+        case 'i':
             i = (i + n - 1) % n;
             break;
 
         case '\n':
         case '\t':
         case KEY_DOWN:
+        case 'k':
             if (++i == n)
                 stop = TRUE;    /* all passed? */
         }