-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposix.c
More file actions
51 lines (41 loc) · 775 Bytes
/
posix.c
File metadata and controls
51 lines (41 loc) · 775 Bytes
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
#include <stdio.h>
#include <sys/ioctl.h>
#include <signal.h>
#include <termios.h>
#include "sim.h"
static void handle(int);
static struct termios initial_state;
extern void
win_end(void)
{
printf(ED CSI "H");
tcsetattr(0, TCSAFLUSH, &initial_state);
}
extern void
win_init(Window* w)
{
struct termios raw_state;
tcgetattr(0, &initial_state);
raw_state = initial_state;
raw_state.c_lflag &= ~(ECHO|ICANON|ISIG);
tcsetattr(0, TCSAFLUSH, &raw_state);
setbuf(stdout, NULL);
printf(CSI "H\t" CSI "6n");
scanf("\x1b[%*d;%huR", &w->t);
--w->t;
handle(SIGWINCH);
}
extern void
win_query(Window* w)
{
struct winsize ws;
ioctl(0, TIOCGWINSZ, &ws);
w->wx = ws.ws_col;
w->wy = ws.ws_row;
}
static void
handle(int sig)
{
resize();
signal(SIGWINCH, handle);
}