From a918fd2cac10e435f21eaa4dce8c0b02b230a2ba Mon Sep 17 00:00:00 2001 From: "R. Eric Wheeler" Date: Mon, 15 Feb 2021 13:20:10 -0800 Subject: [PATCH] Fixed readKey function --- src/Console/Resources/getch.c | 21 ++++++--------------- src/Console/Resources/libgetch.so | Bin 16696 -> 16616 bytes 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/Console/Resources/getch.c b/src/Console/Resources/getch.c index 7e56040..e30ed66 100644 --- a/src/Console/Resources/getch.c +++ b/src/Console/Resources/getch.c @@ -4,12 +4,10 @@ #include #include #include -#include #define CTRL_KEY(k) ((k) & 0x1f) static struct termios oldattr; -static int stdin_flags; /* static char *strrev(char *str) @@ -30,23 +28,15 @@ static char *strrev(char *str) static void setNormalMode(void) { tcsetattr(STDIN_FILENO, TCSANOW, &oldattr); - fcntl(STDIN_FILENO, F_SETFL, stdin_flags); } static void setRawMode(void) { tcgetattr(STDIN_FILENO, &oldattr); - atexit(setNormalMode); struct termios raw = oldattr; - raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); - raw.c_oflag &= ~(OPOST); - raw.c_cflag |= (CS8); - raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG); - raw.c_cc[VMIN] = 0; - raw.c_cc[VTIME] = 1; - + cfmakeraw(&raw); tcsetattr(STDIN_FILENO, TCSANOW, &raw); } @@ -87,12 +77,12 @@ void _ungetc(int c) { int readKey(void) { -int bytesRead; - char key; - while ((key = fgetc(stdin)) == EOF) { - } + + + int key = getchar(); + if (key == '\x1b') { char seq[4]; @@ -161,6 +151,7 @@ int bytesRead; int _getch(void) { + atexit(setNormalMode); setRawMode(); int key = readKey(); diff --git a/src/Console/Resources/libgetch.so b/src/Console/Resources/libgetch.so index 82dae79752af20315d789689f8a515987fd7fc90..3142cc7e347e1feede842fcd6e56bc20525b9480 100755 GIT binary patch delta 3929 zcma))IqR=3JsUU#2M(ypMMNE5qDt475gdMWPcezMHzOVLZd?)_`z zW^&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