From b52f4ee7e7d6deccc64576d8ab7daa056451cebf Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Mon, 6 Feb 2023 01:14:33 -0800 Subject: actually works now --- conio.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'conio.h') diff --git a/conio.h b/conio.h index eee033c..fa866f2 100644 --- a/conio.h +++ b/conio.h @@ -1,4 +1,14 @@ -#ifndef CONIO_H -#define CONIO_H -int getch(void); -#endif +#include +#include +#include +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; +} -- cgit v1.3.1