10 static void cleanup(void);
11 static void sighandler(int s);
13 int term_width, term_height;
15 struct termios saved_term;
17 int main(int argc, char **argv)
27 if((res = read(ttyfd, &c, 1)) == 0 || (res < 0 && errno != EINTR)) {
42 if((ttyfd = open("/dev/tty", O_RDWR)) == -1) {
43 perror("failed to open /dev/tty");
46 if(tcgetattr(ttyfd, &term) == -1) {
47 perror("failed to get terminal attr");
51 term.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
52 term.c_oflag &= ~OPOST;
53 term.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
54 term.c_cflag = (term.c_cflag & ~(CSIZE | PARENB)) | CS8;
56 if(tcsetattr(ttyfd, TCSAFLUSH, &term) == -1) {
57 perror("failed to change terminal attributes");
61 ioctl(1, TIOCGWINSZ, &winsz);
62 term_width = winsz.ws_col;
63 term_height = winsz.ws_row;
65 signal(SIGWINCH, sighandler);
67 write(ttyfd, "\033[2J", 4);
72 static void cleanup(void)
74 tcsetattr(ttyfd, TCSAFLUSH, &saved_term);
78 static void sighandler(int s)
82 signal(s, sighandler);
86 ioctl(1, TIOCGWINSZ, &winsz);
87 term_width = winsz.ws_col;
88 term_height = winsz.ws_row;