From e131669e1460e3492ebecea57869882b68825ea2 Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 26 Jul 2023 23:35:57 +0200 Subject: [PATCH] main2 cross platform --- main2.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/main2.c b/main2.c index e462674..d58a5bc 100644 --- a/main2.c +++ b/main2.c @@ -1,5 +1,40 @@ #include + +#ifdef _WIN32 #include +#else +#include +#include +#include + +/* reads from keypress, doesn't echo */ +int getch(void) +{ + struct termios oldattr, newattr; + int ch; + tcgetattr( STDIN_FILENO, &oldattr ); + newattr = oldattr; + newattr.c_lflag &= ~( ICANON | ECHO ); + tcsetattr( STDIN_FILENO, TCSANOW, &newattr ); + ch = getchar(); + tcsetattr( STDIN_FILENO, TCSANOW, &oldattr ); + return ch; +} + +/* reads from keypress, echoes */ +int getche(void) +{ + struct termios oldattr, newattr; + int ch; + tcgetattr( STDIN_FILENO, &oldattr ); + newattr = oldattr; + newattr.c_lflag &= ~( ICANON ); + tcsetattr( STDIN_FILENO, TCSANOW, &newattr ); + ch = getchar(); + tcsetattr( STDIN_FILENO, TCSANOW, &oldattr ); + return ch; +} +#endif #define ASCII_ESC 27 -- 2.50.1