diff options
| author | Patrick | 2023-07-26 23:35:57 +0200 |
|---|---|---|
| committer | Patrick | 2023-07-26 23:35:57 +0200 |
| commit | e131669e1460e3492ebecea57869882b68825ea2 (patch) | |
| tree | 5947e1954fafe2b1ad044f1ee29eb0bed56c7b29 | |
| parent | 8827b84eeea76b08632d0f7c52488f5af2f83092 (diff) | |
| download | iftint-e131669e1460e3492ebecea57869882b68825ea2.tar.gz iftint-e131669e1460e3492ebecea57869882b68825ea2.zip | |
main2 cross platform
| -rw-r--r-- | main2.c | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -1,5 +1,40 @@ #include <stdio.h>
+
+#ifdef _WIN32
#include <conio.h>
+#else
+#include <termios.h>
+#include <unistd.h>
+#include <stdio.h>
+
+/* 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
|
