From cae75cf30a64158f2120f28df0a02475fb970bcc Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Wed, 16 Mar 2022 18:57:02 +0100 Subject: sfeed_curses: refactor DEC function key parsing First it expected a single digit number, but this way it makes it more easy and logical to add Sun function keys: ESC [ num z For archive/reference Sun function keys relevant to sfeed_curses: num = 214: home 216: page up 220: end 222: page down Noticed on OpenIndiana/Illumos. --- sfeed_curses.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/sfeed_curses.c b/sfeed_curses.c index d0ca7dd..484593b 100644 --- a/sfeed_curses.c +++ b/sfeed_curses.c @@ -2114,24 +2114,26 @@ main(int argc, char *argv[]) case 'D': goto keyleft; /* arrow left */ case 'F': goto endpos; /* end */ case 'H': goto startpos; /* home */ - case '1': /* home */ - case '4': /* end */ - case '5': /* page up */ - case '6': /* page down */ - case '7': /* home: urxvt */ - case '8': /* end: urxvt */ - i = ch; - if ((ch = readch()) < 0) - goto event; - if (ch == '~') { - switch (i) { - case '1': goto startpos; - case '4': goto endpos; - case '5': goto prevpage; - case '6': goto nextpage; - case '7': goto startpos; - case '8': goto endpos; + default: + if (!(ch >= '0' && ch <= '9')) + break; + for (i = ch - '0'; ;) { + if ((ch = readch()) < 0) { + goto event; + } else if (ch >= '0' && ch <= '9') { + i = (i * 10) + (ch - '0'); + continue; + } else if (ch == '~') { /* DEC: ESC [ num ~ */ + switch (i) { + case 1: goto startpos; /* home */ + case 4: goto endpos; /* end */ + case 5: goto prevpage; /* page up */ + case 6: goto nextpage; /* page down */ + case 7: goto startpos; /* home: urxvt */ + case 8: goto endpos; /* end: urxvt */ + } } + break; } } break; -- cgit v1.2.3