Index: madtty.c =================================================================== --- madtty.c (.../vendor/dvtm/current/madtty.c) (revision 20) +++ madtty.c (.../trunk/dvtm/madtty.c) (revision 20) @@ -1190,13 +1201,23 @@ t->cols = cols; } - while (t->rows < rows) { - lines[t->rows].text = (wchar_t *)calloc(sizeof(wchar_t), t->maxcols); - lines[t->rows].attr = (uint16_t *)calloc(sizeof(uint16_t), t->maxcols); - lines[t->rows].fg = calloc(sizeof(short), t->maxcols); - lines[t->rows].bg = calloc(sizeof(short), t->maxcols); - t_row_set(lines + t->rows, 0, t->maxcols, 0); - t->rows++; + int deltarows = 0; + if (t->rows < rows) { + while (t->rows < rows) { + lines[t->rows].text = (wchar_t *)calloc(sizeof(wchar_t), t->maxcols); + lines[t->rows].attr = (uint16_t *)calloc(sizeof(uint16_t), t->maxcols); + lines[t->rows].fg = calloc(sizeof(short), t->maxcols); + lines[t->rows].bg = calloc(sizeof(short), t->maxcols); + t_row_set(lines + t->rows, 0, t->maxcols, 0); + t->rows++; + } + + /* Prepare for backfill */ + if (t->curs_row >= t->scroll_bot - 1) { + deltarows = t->lines + rows - t->curs_row - 1; + if (deltarows > t->scroll_buf_len) + deltarows = t->scroll_buf_len; + } } t->curs_row += lines - t->lines; @@ -1204,6 +1225,13 @@ t->scroll_bot = lines + rows; t->lines = lines; clamp_cursor_to_bounds(t); + + /* Perform backfill */ + if (deltarows > 0) { + fill_scroll_buf(t, -deltarows); + t->curs_row += deltarows; + } + ioctl(t->pty, TIOCSWINSZ, &ws); kill(-t->childpid, SIGWINCH); }