--- rxvt-unicode/src/screen.C 2005/12/21 19:50:17 1.186 +++ rxvt-unicode/src/screen.C 2005/12/26 21:30:04 1.194 @@ -241,8 +241,6 @@ * add or delete rows as appropriate */ - printf ("resize %d:%d => %d:%d\n", prev_nrow, prev_ncol, nrow, ncol);//D - rxvt_salloc *old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t)); rxvt_salloc *old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); @@ -257,9 +255,9 @@ } #endif - drawn_buf = (line_t *) rxvt_realloc (drawn_buf, nrow * sizeof (line_t)); - temp_buf = (line_t *) rxvt_realloc (temp_buf , nrow * sizeof (line_t)); - swap_buf = (line_t *) rxvt_realloc (swap_buf , nrow * sizeof (line_t)); + drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t)); + temp_buf = (line_t *)rxvt_realloc (temp_buf , nrow * sizeof (line_t)); + swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t)); for (int row = min (nrow, prev_nrow); row--; ) { @@ -275,88 +273,131 @@ line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); - // re-wrap lines, this is rather ugly, possibly because I am too dumb - // to come up with a lean and mean algorithm. - - int p = MOD (term_start + nrow , prev_total_rows); // previous row - int pend = MOD (term_start - nsaved, prev_total_rows); + int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row + int pend = MOD (term_start - nsaved , prev_total_rows); int q = total_rows; // rewrapped row - while (p != pend && q > 0) + if (nsaved) { - p = MOD (p - 1, prev_total_rows); + // re-wrap lines, this is rather ugly, possibly because I am too dumb + // to come up with a lean and mean algorithm. - assert (old_buf [MOD (p, prev_total_rows)].t); - assert (!old_buf [MOD (p, prev_total_rows)].is_longer ()); + row_col_t ocur = screen.cur; + ocur.row = MOD (term_start + ocur.row, prev_total_rows); - int llen = old_buf [MOD (p, prev_total_rows)].l; - - while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) + do { p = MOD (p - 1, prev_total_rows); +#ifdef DEBUG_STRICT + assert (old_buf [MOD (p, prev_total_rows)].t); +#endif - llen += prev_ncol; - } + int plines = 1; + int llen = old_buf [MOD (p, prev_total_rows)].l; - int qlines = llen / ncol + 1; - int lofs = 0; + while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) + { + p = MOD (p - 1, prev_total_rows); - q -= qlines; + plines++; + llen += prev_ncol; + } - int qrow = q; + int qlines = max (0, (llen - 1) / ncol) + 1; - for (; qlines--; qrow++) - { - if (qrow >= 0) - { - line_t &qline = row_buf [qrow]; + // drop partial lines completely + if (q < qlines) + break; + + q -= qlines; - lalloc (qline); - qline.set_is_longer (); + int lofs = 0; + line_t *qline; + + // re-assemble the full line by destination lines + for (int qrow = q; qlines--; qrow++) + { + qline = row_buf + qrow; + lalloc (*qline); + qline->set_is_longer (); int qcol = 0; - for (;;) + // fill a single destination line + while (lofs < llen && qcol < ncol) { - int prow = lofs / prev_ncol + p; + int prow = lofs / prev_ncol; int pcol = lofs % prev_ncol; - line_t &pline = old_buf [p]; + prow = MOD (p + prow, prev_total_rows); - int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); + // we only adjust the cursor _row_ and put it into + // the topmost line of "long line" it was in, as + // this seems to upset applications/shells/readline + // least. + if (prow == ocur.row) + screen.cur.row = q - (total_rows - nrow); - printf ("q %d lofs %d>%d len %d pq %d:%d p %d:%d q :%d\n", q, llen, lofs, len, prev_ncol, ncol, prow, pcol, qcol); + line_t &pline = old_buf [prow]; - if (len <= 0) - { - qline.l = qcol; - scr_blank_line (qline, qcol, ncol - qcol, DEFAULT_RSTYLE); - break; - } + int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); - assert (lofs < 1000); + assert (len); + assert (pline.t); - memcpy (qline.t + qcol, pline.t + pcol, len * sizeof (text_t)); - memcpy (qline.r + qcol, pline.r + pcol, len * sizeof (rend_t)); + memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); + memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t)); lofs += len; qcol += len; - - if (qcol == ncol) - break; } } - else - lofs += ncol; + + qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1; + scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); } + while (p != pend && q > 0); + + term_start = total_rows - nrow; + nsaved = term_start - q; + + // make sure all terminal lines exist + while (nsaved < 0) + scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); + } + else + { + // if no scrollback exists (yet), wing, instead of wrap + + for (int row = min (nrow, prev_nrow); row--; ) + { + line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)]; + line_t &qline = row_buf [row]; + + qline = pline; + lresize (qline); + } + + for (int row = prev_nrow; row < nrow; row++) + { + row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE); + } + + term_start = 0; + } + +#ifdef DEBUG_STRICT //TODO: remove + for (int i = -nsaved; i < nrow; i++) + assert (ROW (i).t); +#endif free (old_buf); delete old_ta; delete old_ra; - min_it (screen.cur.row, nrow - 1); - min_it (screen.cur.col, ncol - 1); + clamp_it (screen.cur.row, 0, nrow - 1); + clamp_it (screen.cur.col, 0, ncol - 1); if (tabs) free (tabs); @@ -388,6 +429,8 @@ free (drawn_buf); free (temp_buf); free (tabs); + + row_buf = 0; // signal that we freed all the arrays } /* ------------------------------------------------------------------------- */ @@ -453,9 +496,6 @@ #ifdef DEBUG_STRICT assert (s->cur.row >= 0); assert (s->cur.col >= 0); -#else /* drive with your eyes closed */ - max_it (s->cur.row, 0); - max_it (s->cur.col, 0); #endif } @@ -489,7 +529,7 @@ { num_scr = 0; - for (int i = nrow; i--; ) + for (int i = prev_nrow; i--; ) ::swap (ROW(i), swap_buf [i]); ::swap (screen.charset, swap.charset); @@ -582,7 +622,13 @@ selection.end.row -= count; selection.mark.row -= count; - selection_check (0); + if (selection.beg.row < -nsaved + || selection.end.row < -nsaved + || selection.mark.row < -nsaved) + { + CLEAR_ALL_SELECTION (); + selection.op = SELECTION_CLEAR; + } } for (int i = count; i--; ) @@ -597,20 +643,17 @@ { if (selection.op && current_screen == selection.screen) { - int i = selection.beg.row; - int j = selection.end.row; - - if ((i < row1 && j > row1) - || (i < row2 && j > row2) - || (i - count < row1 && i >= row1) - || (i - count > row2 && i <= row2) - || (j - count < row1 && j >= row1) - || (j - count > row2 && j <= row2)) + if ((selection.beg.row < row1 && selection.end.row > row1) + || (selection.beg.row < row2 && selection.end.row > row2) + || (selection.beg.row - count < row1 && selection.beg.row >= row1) + || (selection.beg.row - count > row2 && selection.beg.row <= row2) + || (selection.end.row - count < row1 && selection.end.row >= row1) + || (selection.end.row - count > row2 && selection.end.row <= row2)) { CLEAR_ALL_SELECTION (); - selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ + selection.op = SELECTION_CLEAR; } - else if (j >= row1 && j <= row2) + else if (selection.end.row >= row1 && selection.end.row <= row2) { /* move selected region too */ selection.beg.row -= count; @@ -655,7 +698,7 @@ unsigned char checksel; unicode_t c; - int row, last_col; + int last_col; const unicode_t *strend = str + len; want_refresh = 1; @@ -679,11 +722,8 @@ assert (screen.cur.col < last_col); assert (screen.cur.row < nrow && screen.cur.row >= -nsaved); -#else /* drive with your eyes closed */ - min_it (screen.cur.col, last_col - 1); - clamp_it (screen.cur.row, -nsaved, nrow - 1); #endif - row = screen.cur.row; + int row = screen.cur.row; checksel = selection.op && current_screen == selection.screen ? 1 : 0; @@ -902,8 +942,6 @@ #ifdef DEBUG_STRICT assert (screen.cur.row >= 0); -#else /* drive with your eyes closed */ - max_it (screen.cur.row, 0); #endif } @@ -952,9 +990,7 @@ return; else if (count > 0) { - int row = screen.cur.row; - - line_t &l = ROW(row); + line_t &l = ROW(screen.cur.row); rend_t base_rend = l.r[i]; ht &= l.t[i] == ' '; @@ -1039,16 +1075,12 @@ void rxvt_term::scr_forwardindex () { - int row; - if (screen.cur.col < ncol - 1) scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); else { - row = screen.cur.row; - - if (ROW(row).is_longer ()) //TODO//FIXME//LEN - ROW(row).l = ncol; + if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN + ROW(screen.cur.row).l = ncol; scr_gotorc (0, 0, R_RELATIVE); scr_insdel_chars (1, DELETE); @@ -1141,21 +1173,21 @@ void rxvt_term::scr_erase_line (int mode) { - unsigned int row, col, num; + unsigned int col, num; want_refresh = 1; ZERO_SCROLLBACK (); selection_check (1); - row = screen.cur.row; + line_t &line = ROW(screen.cur.row); switch (mode) { case 0: /* erase to end of line */ col = screen.cur.col; num = ncol - col; - min_it (ROW(row).l, col); + min_it (line.l, col); if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) CLEAR_SELECTION (); @@ -1170,7 +1202,7 @@ case 2: /* erase whole line */ col = 0; num = ncol; - ROW(row).l = 0; + line.l = 0; if (selection.beg.row <= screen.cur.row && selection.end.row >= screen.cur.row) CLEAR_SELECTION (); @@ -1179,7 +1211,7 @@ return; } - scr_blank_line (ROW(row), col, num, rstyle); + scr_blank_line (line, col, num, rstyle); } /* ------------------------------------------------------------------------- */ @@ -1693,14 +1725,6 @@ } #endif -#ifdef DEBUG_STRICT -#if 0 - // that's not debugging //TODO //FIXME - clamp_it (x, 0, width); - clamp_it (y, 0, height); -#endif -#endif - /* round down */ rc[PART_BEG].col = Pixel2Col (x); rc[PART_BEG].row = Pixel2Row (y);