diff --git a/src/Console/Resources/getch.c b/src/Console/Resources/getch.c index eb21e46..126072c 100644 --- a/src/Console/Resources/getch.c +++ b/src/Console/Resources/getch.c @@ -1,19 +1,37 @@ #include #include #include +#include +static struct termios oldattr; + +static void setRawMode(void) +{ + struct termios newattr; + + tcgetattr(STDIN_FILENO, &oldattr); + newattr = oldattr; + cfmakeraw(&newattr); + tcsetattr(STDIN_FILENO, TCSANOW, &newattr); + +} +static void setNormalMode(void) +{ + tcsetattr(STDIN_FILENO, TCSANOW, &oldattr); +} + /* reads from keypress, doesn't echo */ int _getch(void) { - struct termios oldattr, newattr; int ch; - tcgetattr( STDIN_FILENO, &oldattr ); - newattr = oldattr; - cfmakeraw(&newattr); - //newattr.c_lflag &= ~( ICANON | ECHO ); - //tcsetattr( STDIN_FILENO, TCSANOW, &newattr ); + + setRawMode(); + atexit(setNormalMode); + ch = getchar(); - tcsetattr( STDIN_FILENO, TCSANOW, &oldattr ); + + setNormalMode(); + return ch; } diff --git a/src/Console/Resources/libgetch.so b/src/Console/Resources/libgetch.so index 40fffa8..358a814 100755 Binary files a/src/Console/Resources/libgetch.so and b/src/Console/Resources/libgetch.so differ