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
60
61
62
63
64
65
66
|
#include "tctl.h"
#include "../sys/ioctl.h"
#define GET_WIN_SIZE 0x5413
#define SET_WIN_SIZE 0x5414
#define TC_GET_ATTR 0x5401
#define TC_SET_ATTR 0x5402
#define FD_FLUSH 0x000b
#define ICANON 000002
#define ECHO 000010
window_size_t tctl_get_window_size()
{
window_size_t ws;
ioctl(1, GET_WIN_SIZE, &ws);
return ws;
}
void tctl_set_window_size(window_size_t size)
{
ioctl(1, SET_WIN_SIZE, &size);
}
int isatty()
{
termios_t term;
return ioctl(1, TC_GET_ATTR, &term) == 0;
}
int tcgetattr(int fd, termios_t *termios)
{
return ioctl(fd, TC_GET_ATTR, termios);
}
void tcsetattr(int fd, termios_t *termios)
{
ioctl(fd, TC_SET_ATTR, termios);
}
void setcanonical(termios_t *term, int is_canonical)
{
if (is_canonical)
term->c_lflag |= ICANON;
else
term->c_lflag &= ~ICANON;
}
void setecho(termios_t *term, int is_echo)
{
if (is_echo)
term->c_lflag |= ECHO;
else
term->c_lflag &= ~ECHO;
}
void flush(unsigned int fd)
{
ioctl(fd, FD_FLUSH, 0);
}
|