diff options
Diffstat (limited to 'desktop/term.cc')
| -rwxr-xr-x | desktop/term.cc | 28 |
1 files changed, 28 insertions, 0 deletions
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 @@ | |||
| 1 | #include "term.h" | ||
| 2 | |||
| 3 | #include <cstdio> | ||
| 4 | #include <unistd.h> //_getch*/ | ||
| 5 | #include <termios.h> //_getch*/ | ||
| 6 | |||
| 7 | char getch () | ||
| 8 | { | ||
| 9 | char buf=0; | ||
| 10 | struct termios old={0}; | ||
| 11 | fflush(stdout); | ||
| 12 | if(tcgetattr(0, &old)<0) | ||
| 13 | perror("tcsetattr()"); | ||
| 14 | old.c_lflag&=~ICANON; | ||
| 15 | old.c_lflag&=~ECHO; | ||
| 16 | old.c_cc[VMIN]=1; | ||
| 17 | old.c_cc[VTIME]=0; | ||
| 18 | if(tcsetattr(0, TCSANOW, &old)<0) | ||
| 19 | perror("tcsetattr ICANON"); | ||
| 20 | if(read(0,&buf,1)<0) | ||
| 21 | perror("read()"); | ||
| 22 | old.c_lflag|=ICANON; | ||
| 23 | old.c_lflag|=ECHO; | ||
| 24 | if(tcsetattr(0, TCSADRAIN, &old)<0) | ||
| 25 | perror ("tcsetattr ~ICANON"); | ||
| 26 | printf("%c\n",buf); | ||
| 27 | return buf; | ||
| 28 | } | ||
