From 3844fbb3d4be958ccbc0c8328b011adf1b409f65 Mon Sep 17 00:00:00 2001 From: Can202 Date: Mon, 27 Sep 2021 13:46:31 -0300 Subject: [PATCH] linux_extra --- linux_extra/conio.h | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 linux_extra/conio.h diff --git a/linux_extra/conio.h b/linux_extra/conio.h new file mode 100644 index 0000000..b1c9960 --- /dev/null +++ b/linux_extra/conio.h @@ -0,0 +1,53 @@ +/* + * This is conio.h compatible header file for gcc. +*/ + +#ifndef _CONIO_H +#define _CONIO_H 1 + +#include +#include +#include +#include + +void clrscr() +{ + system("clear"); +} + +void gotoxy(int x,int y) +{ + printf("%c[%d;%df",0x1B,y,x); +} + +/* 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 /* conio.h */ + +