catpoint

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

commit 0156d8ef295e34fe28c135218df865f2b4041635
parent 2b32e6dd7e883e45d8ba9e0cea896984a6cf9902
Author: Lazaros Koromilas <lostd@2f30.org>
Date:   Sat,  9 Feb 2019 20:13:22 +0200

Revert "Add arrow-key-support"

This reverts commit 26221fab523ab770e5882099dcab9793245a047e.

Diffstat:
Mcatpoint.c | 53+++++++++++++++++++++++++++++++----------------------
1 file changed, 31 insertions(+), 22 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, codekey; + int c, i, fd; struct slide *s; struct stat sb; static struct termios oldterm, newterm; @@ -51,33 +51,42 @@ main(int argc, char *argv[]) tcsetattr(STDIN_FILENO, TCSANOW, &newterm); printf("\033[?25l"); /* hide cursor */ - i = 0; /* start */ + /* start */ + i = 0; show: /* clear screen and display slide */ printf("\x1b[2J\x1b[H" "%.*s", (int)s[i].siz, s[i].buf); again: c = getchar(); - 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; + 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; } - /* 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);