- int nb;
-
- nb = madtty_read(rt, buf + pos, sizeof(buf) - pos);
- if (nb <= 0)
- continue;
- pos += nb;
-
- nb = madtty_inject(rt, buf, pos);
- if (nb <= 0)
- continue;
- memmove(buf, buf + nb, pos - nb);
- pos -= nb;
+ if (FD_ISSET(rt->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();