From e62be3b12d3c94d709a77d89f52c31f7c4ac475d Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 4 Dec 2021 22:22:47 -0800 Subject: Initial commit. --- desktop/term.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 desktop/term.cc (limited to 'desktop/term.cc') diff --git a/desktop/term.cc b/desktop/term.cc new file mode 100755 index 0000000..a72f1e9 --- /dev/null +++ b/desktop/term.cc @@ -0,0 +1,28 @@ +#include "term.h" + +#include +#include //_getch*/ +#include //_getch*/ + +char getch () +{ + char buf=0; + struct termios old={0}; + fflush(stdout); + if(tcgetattr(0, &old)<0) + perror("tcsetattr()"); + old.c_lflag&=~ICANON; + old.c_lflag&=~ECHO; + old.c_cc[VMIN]=1; + old.c_cc[VTIME]=0; + if(tcsetattr(0, TCSANOW, &old)<0) + perror("tcsetattr ICANON"); + if(read(0,&buf,1)<0) + perror("read()"); + old.c_lflag|=ICANON; + old.c_lflag|=ECHO; + if(tcsetattr(0, TCSADRAIN, &old)<0) + perror ("tcsetattr ~ICANON"); + printf("%c\n",buf); + return buf; + } -- cgit v1.2.3