posix.c (691B)
1 #include <sys/ioctl.h> 2 #include <stdio.h> 3 #include <termios.h> 4 5 #include "sim.h" 6 7 void win_end(void); 8 void win_init(Window* w); 9 void win_query(Window* w); 10 11 static struct termios initial_state; 12 13 void 14 win_end(void) 15 { 16 printf(ED CSI "H"); 17 tcsetattr(0, TCSAFLUSH, &initial_state); 18 } 19 20 void 21 win_init(Window* w) 22 { 23 struct termios raw_state; 24 25 tcgetattr(0, &initial_state); 26 raw_state = initial_state; 27 raw_state.c_lflag &= ~(ECHO|ICANON|ISIG); 28 tcsetattr(0, TCSAFLUSH, &raw_state); 29 setbuf(stdout, NULL); 30 printf(CSI "H\t" CSI "6n"); 31 scanf("\x1b[%*d;%huR", &w->t); 32 --w->t; 33 } 34 35 void 36 win_query(Window* w) 37 { 38 struct winsize ws; 39 40 ioctl(0, TIOCGWINSZ, &ws); 41 w->wx = ws.ws_col; 42 w->wy = ws.ws_row; 43 }