diff options
| author | Jan Tuomi <jan-sebastian.tuomi@aalto.fi> | 2016-10-09 12:56:59 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan-sebastian.tuomi@aalto.fi> | 2016-10-09 14:50:24 +0300 |
| commit | 7c9146efca9b565777e1093e65272f710ae5d0d9 (patch) | |
| tree | 7077241a78ee1f8d9a7044b08eb4714ad47f4020 /utils.cpp | |
| parent | 88996781bd89825501ae18a1ce6e7744e767db86 (diff) | |
Add editor content outputting
Diffstat (limited to 'utils.cpp')
| -rw-r--r-- | utils.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/utils.cpp b/utils.cpp new file mode 100644 index 0000000..f118fc5 --- /dev/null +++ b/utils.cpp @@ -0,0 +1,27 @@ +#include "utils.h" +#include <unistd.h> //_getch +#include <termios.h> //_getch +#include <stdio.h> + +/* Thanks to StackOverflow user mf_ */ +char Utils::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; + } |
