-
Notifications
You must be signed in to change notification settings - Fork 5
/
emacs.c
59 lines (39 loc) · 943 Bytes
/
emacs.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <termios.h>
#include <sys/ioctl.h>
struct termios raw;
struct winsize size;
int raw_on(void)
{
if (tcgetattr(0, &raw) == -1)
return -1;
raw.c_lflag &= ~ECHO;
raw.c_lflag &= ~ICANON;
raw.c_lflag &= ~ISIG;
// raw.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
// raw.c_oflag &= ~(OPOST);
// raw.c_cflag |= (CS8);
// raw.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
// raw.c_cc[VMIN] = 1;
// raw.c_cc[VTIME] = 0;
return tcsetattr(0, TCSAFLUSH, &raw);
}
int raw_off(void)
{
if (tcgetattr(0, &raw) == -1)
return -1;
raw.c_lflag |= ECHO;
raw.c_lflag |= ICANON;
raw.c_lflag |= ISIG;
return tcsetattr(0, TCSAFLUSH, &raw);
}
int get_row(void)
{
ioctl(0, TIOCGWINSZ, &size);
return size.ws_row;
}
int get_col(void)
{
ioctl(0, TIOCGWINSZ, &size);
return size.ws_col;
}