From 382ca844d5acc32905ee81639e29db247f0caacd Mon Sep 17 00:00:00 2001 From: "R. Eric Wheeler" Date: Thu, 7 Jan 2021 15:55:29 -0800 Subject: [PATCH] Organized getch.c a little more --- src/Console/Resources/getch.c | 32 +++++++++++++++++++++++------- src/Console/Resources/libgetch.so | Bin 16136 -> 16392 bytes 2 files changed, 25 insertions(+), 7 deletions(-) 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 40fffa8abc246a5f75a2c3167d017bae6609d1b4..358a81446fa512e2a557cab173e6e0a8aa264872 100755 GIT binary patch delta 2127 zcmZ8iZERCj7(VB=9lKjs+HFlcVC+ss7)U?X?xT#APFJ{u56jGwMS-r_2NWT&QNm(~ z>jE)t>XL0QDEJY#Uru9mqlv2tV8I`tiE;dp4>bxuFePC4_+gfa*7w|VFAPp{&U4=9 zdEfJO&v|d+?L?f8*h{C(L@5CdB;gxfSzja-a8oK6-Qy6i3*5RsI^is8q}*tvqrW)B zkSb-sLU)O+>L9H!M2}XK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