-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEscFunc.hpp
45 lines (36 loc) · 919 Bytes
/
EscFunc.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef EscFunc
#define EscFunc
#include <iostream>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
namespace nc{
void gettermsize(int* width, int* height) {
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
*width=w.ws_col;
*height=w.ws_row;
}
std::streambuf *cinbuf=std::cin.rdbuf();
char cinchr(){
char c;
read(STDIN_FILENO, &c, 1);
return c;
}
char ubCinchr(){
struct termios raw;
tcgetattr(STDIN_FILENO, &raw);
raw.c_cc[VTIME] = 1;
raw.c_cc[VMIN] = 0;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
char c='\0';
read(STDIN_FILENO, &c, 1);
struct termios unraw;
tcgetattr(STDIN_FILENO, &unraw);
unraw.c_cc[VTIME] = 1;
unraw.c_cc[VMIN] = 1;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &unraw);
return c;
}
}
#endif