From 4424d94121b1a66eb60edcaeb38ada191a7d3657 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Wed, 8 May 2024 23:55:23 +0200 Subject: [PATCH] support vi keys (:ijkl) --- cmore.c | 4 ++++ tui.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cmore.c b/cmore.c index 9b08436..33fb276 100644 --- 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 c83211c..231f283 100644 --- 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? */ } -- 2.30.2