catpoint

simple slides viewer
git clone git://git.2f30.org/catpoint.git
Log | Files | Refs | README | LICENSE

commit 26221fab523ab770e5882099dcab9793245a047e
parent 579a40724bd2943996bca41b63691b45728ce875
Author: FRIGN <dev@frign.de>
Date:   Sun Jul 20 13:19:24 +0200

Add arrow-key-support

Conflicts:
	catpoint.c

Diffstat:
catpoint.c | 53++++++++++++++++++++++-------------------------------
1 file changed, 22 insertions(+), 31 deletions(-)
diff --git a/catpoint.c b/catpoint.c @@ -17,7 +17,7 @@ struct slide { int main(int argc, char *argv[]) { - int c, i, fd; + int c, i, fd, codekey; struct slide *s; struct stat sb; static struct termios oldterm, newterm; @@ -51,42 +51,33 @@ main(int argc, char *argv[]) tcsetattr(STDIN_FILENO, TCSANOW, &newterm); printf("\033[?25l"); /* hide cursor */ - /* start */ - i = 0; + i = 0; /* start */ show: /* clear screen and display slide */ printf("\x1b[2J\x1b[H" "%.*s", (int)s[i].siz, s[i].buf); again: c = getchar(); - switch (c) { - case 'q': - break; - /* next */ - case 'l': - case 'j': - case 'C': /* right */ - case 'B': /* down */ - if (i < argc - 1) { - i++; - goto show; - } - goto again; - /* prev */ - case 'h': - case 'k': - case 'D': /* left */ - case 'A': /* up */ - if (i > 0) { - i--; - goto show; - } - goto again; - case '\033': - case '[': - default: - goto again; + if (c == 'q') { + goto end; + } else if (i < argc - 1 + && (c == 'l' || c == 'j' + || (codekey == 2 && (c == 'A' || c == 'C')))) { /* next */ + i++; + goto show; + } else if (i > 0 + && (c == 'h' || c == 'k' + || (codekey == 2 && (c == 'B' || c == 'D')))) { /* prev */ + i--; + goto show; } - + /* handle keycode state */ + codekey = (codekey == 2) ? 0 : codekey; + if (c == '\033') + codekey = 1; + else if (c == '[' && codekey == 1) + codekey = 2; + goto again; +end: /* unmap mem */ for (i = 0; i < argc; ++i) munmap(s[i].buf, s[i].siz);