- usleep(10000);
- rote_vt_draw(rt, term_win, 1, 1, NULL);
- wrefresh(term_win);
-
- ch = getch();
- if (ch != ERR)
- rote_vt_keypress(rt, ch); /* pass the keypress for handling */
+ struct timeval tv = { 0, 1000 * 1000 / 100 };
+ fd_set rfds;
+ int ch;
+
+ FD_ZERO(&rfds);
+ FD_SET(0, &rfds);
+ FD_SET(pty, &rfds);
+
+ if (select(pty + 1, &rfds, NULL, NULL, &tv) > 0) {
+ if (FD_ISSET(pty, &rfds)) {
+ madtty_process(rt);
+ dirty = 1;
+ }
+ }
+
+ if (sigwinch) {
+ int fd, cols = -1, rows = -1;
+ struct winsize w;
+
+ if ((fd = open("/dev/tty", O_RDONLY)) != -1) {
+ if (ioctl(fd, TIOCGWINSZ, &w) != -1) {
+ rows = w.ws_row;
+ cols = w.ws_col;
+ }
+ close(fd);
+ }
+ if (rows <= 0) {
+ rows = atoi(getenv("LINES") ?: "24");
+ }
+ if (cols <= 0) {
+ cols = atoi(getenv("COLUMNS") ?: "80");
+ }
+
+ resizeterm(rows, cols);
+ madtty_resize(rt, rows - 2, cols - 2);
+ wresize(term_win, rows - 2, cols - 2);
+ sigwinch = 0;
+ erase();
+ }
+
+ while ((ch = getch()) != ERR) {
+ madtty_keypress(rt, ch); /* pass the keypress for handling */
+ dirty = 1;
+ }
+
+ gettimeofday(&tv, NULL);
+ if (dirty && is_expired(tv, next)) {
+ madtty_draw(rt, term_win, 0, 0);
+ wrefresh(term_win);
+ dirty = 0;
+ next = timeval_add(tv, slice);
+ }