-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.c
43 lines (33 loc) · 723 Bytes
/
io.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
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include "io.h"
#include "utf8.h"
char getkey()
{
#ifndef debug
size_t slen = u8_strlen("\\u001b[8m");
char* buf = calloc(slen + 1, sizeof(char));
u8_unescape(buf, slen, "\\u001b[8m");
printf("%s", buf);
free(buf);
#endif
struct termios attr;
tcgetattr(0, &attr);
attr.c_lflag &= ~ICANON;
tcsetattr(0, TCSANOW, &attr);
fflush(stdin);
int c;
while((c = getchar()) == EOF);
attr.c_lflag |= ICANON;
tcsetattr(0, TCSANOW, &attr);
fflush(stdin);
#ifndef debug
slen = u8_strlen("\\u001b[28m\r");
buf = calloc(slen + 1, sizeof(char));
u8_unescape(buf, slen, "\\u001b[28m\r");
printf("%s", buf);
free(buf);
#endif
return c;
}