commit 578d7d274b4086be7fcd67b65dffddc9cbdd931a
parent 29b1fa9c76379804b63dee3ab2268462025d557b
Author: Lazaros Koromilas <lostd@2f30.org>
Date: Sat, 9 Feb 2019 20:14:48 +0200
Revert "Get rid of ncurses"
This reverts commit f79c989fd7b8ab805931f8b6e50240d06d24fca7.
Diffstat:
M | catpoint.c | | | 36 | +++++++++++++++++------------------- |
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/catpoint.c b/catpoint.c
@@ -4,11 +4,11 @@
#include <sys/mman.h>
#include <err.h>
+#include <curses.h>
#include <fcntl.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
-#include <termios.h>
#include <unistd.h>
struct slide {
@@ -19,7 +19,7 @@ struct slide {
static void
printslide(struct slide *s)
{
- printf("%.*s", (int)s->siz, s->buf);
+ printw("%.*s", (int)s->siz, s->buf);
}
int
@@ -28,7 +28,6 @@ main(int argc, char *argv[])
int c, i, fd;
struct slide *s;
struct stat sb;
- static struct termios oldterm, newterm;
if (argc == 1)
errx(1, "usage: %s file ...", argv[0]);
@@ -54,29 +53,31 @@ main(int argc, char *argv[])
close(fd);
}
- /* set up terminal */
- tcgetattr(STDIN_FILENO, &oldterm);
- newterm = oldterm;
- newterm.c_lflag &= ~(ECHO | ICANON);
- tcsetattr(STDIN_FILENO, TCSANOW, &newterm);
- printf("\e[?25l"); /* hide cursor */
+ /* init curses */
+ initscr();
+ cbreak();
+ noecho();
+ nonl();
+ intrflush(stdscr, FALSE);
+ keypad(stdscr, TRUE);
+ curs_set(FALSE); /* hide cursor */
/* start */
i = 0;
show:
/* display slide */
- printf("\x1b[2J\x1b[H"); /* clear */
+ clear();
printslide(&s[i]);
again:
- c = getchar();
+ c = getch();
switch (c) {
case 'q':
break;
/* next */
case 'l':
case 'j':
- case 'C': /* right */
- case 'B': /* down */
+ case KEY_RIGHT:
+ case KEY_DOWN:
if (i < argc - 1) {
i++;
goto show;
@@ -85,15 +86,13 @@ again:
/* prev */
case 'h':
case 'k':
- case 'D': /* left */
- case 'A': /* up */
+ case KEY_LEFT:
+ case KEY_UP:
if (i > 0) {
i--;
goto show;
}
goto again;
- case '\033':
- case '[':
default:
goto again;
}
@@ -103,8 +102,7 @@ again:
munmap(s[i].buf, s[i].siz);
free(s);
- printf("\e[?25h"); /* unhide cursor */
- tcsetattr(STDIN_FILENO, TCSANOW, &oldterm); /* restore terminal */
+ endwin(); /* restore terminal */
return (0);
}