commit 0772f96752a8adc95fe952f1edd3bb4a680da861
parent 8461c35b9151418b3839c60b23931dce132d3062
Author: Claudio Alessi <smoppy@gmail.com>
Date: Mon, 22 Jul 2019 10:44:44 +0200
Use read(2) instead of getchar().
Diffstat:
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/globox.c b/globox.c
@@ -23,6 +23,7 @@
#include <sys/ioctl.h>
#include <termios.h>
#include <time.h>
+#include <unistd.h>
#include "arg.h"
char *argv0;
@@ -136,6 +137,7 @@ int mvprintf(int x, int y, char *fmt, ...);
Object *objbysym(char sym);
void objwalk(Object *o, int offset);
void quit(const Arg *arg);
+int readchar(void);
void resize(int x, int y);
void restart(const Arg *arg);
void run(void);
@@ -259,6 +261,7 @@ choose(char *opts, const char *msgstr, ...) {
fprintf(stdout, CURPOS, cols - 1, 0);
vfprintf(stdout, msgstr, ap);
va_end(ap);
+ fflush(stdout);
ioblock(1);
while(!(o && *o) && (c = getkey()) != EOF) {
@@ -462,11 +465,11 @@ freescene(void) {
/* XXX quick'n dirty implementation */
int
getkey(void) {
- int key = getchar(), c;
+ int key = readchar(), c;
- if(key != '\x1b' || getchar() != '[')
+ if(key != '\x1b' || readchar() != '[')
return key;
- switch((c = getchar())) {
+ switch((c = readchar())) {
case 'A': key = KeyUp; break;
case 'B': key = KeyDown; break;
case 'C': key = KeyRight; break;
@@ -634,6 +637,12 @@ quit(const Arg *arg) {
running = 0;
}
+int
+readchar(void) {
+ char buf[1] = {0};
+ return (read(0, buf, 1) < 1 ? EOF : buf[0]);
+}
+
void
resize(int x, int y) {
rows = x;