ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/screen.C
(Generate patch)

Comparing rxvt-unicode/src/screen.C (file contents):
Revision 1.188 by root, Thu Dec 22 00:07:47 2005 UTC vs.
Revision 1.198 by root, Tue Dec 27 01:25:42 2005 UTC

271 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); 271 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
272 } 272 }
273 273
274 line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); 274 line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
275 275
276 // re-wrap lines, this is rather ugly, possibly because I am too dumb
277 // to come up with a lean and mean algorithm.
278
279 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row 276 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
280 int pend = MOD (term_start - nsaved , prev_total_rows); 277 int pend = MOD (term_start - nsaved , prev_total_rows);
281 int q = total_rows; // rewrapped row 278 int q = total_rows; // rewrapped row
282 279
283 while (p != pend && q > 0) 280 if (nsaved)
281 {
282 // re-wrap lines, this is rather ugly, possibly because I am too dumb
283 // to come up with a lean and mean algorithm.
284
285 row_col_t ocur = screen.cur;
286 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
287
284 { 288 do
285 p = MOD (p - 1, prev_total_rows);
286#ifdef DEBUG_STRICT
287 assert (old_buf [MOD (p, prev_total_rows)].t);
288#endif
289
290 int llen = old_buf [MOD (p, prev_total_rows)].l;
291
292 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
293 { 289 {
294 p = MOD (p - 1, prev_total_rows); 290 p = MOD (p - 1, prev_total_rows);
291#ifdef DEBUG_STRICT
292 assert (old_buf [MOD (p, prev_total_rows)].t);
293#endif
295 294
295 int plines = 1;
296 int llen = old_buf [MOD (p, prev_total_rows)].l;
297
298 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ())
299 {
300 p = MOD (p - 1, prev_total_rows);
301
302 plines++;
296 llen += prev_ncol; 303 llen += prev_ncol;
304 }
305
306 int qlines = max (0, (llen - 1) / ncol) + 1;
307
308 // drop partial lines completely
309 if (q < qlines)
310 break;
311
312 q -= qlines;
313
314 int lofs = 0;
315 line_t *qline;
316
317 // re-assemble the full line by destination lines
318 for (int qrow = q; qlines--; qrow++)
319 {
320 qline = row_buf + qrow;
321 lalloc (*qline);
322 qline->set_is_longer ();
323
324 int qcol = 0;
325
326 // fill a single destination line
327 while (lofs < llen && qcol < ncol)
328 {
329 int prow = lofs / prev_ncol;
330 int pcol = lofs % prev_ncol;
331
332 prow = MOD (p + prow, prev_total_rows);
333
334 // we only adjust the cursor _row_ and put it into
335 // the topmost line of "long line" it was in, as
336 // this seems to upset applications/shells/readline
337 // least.
338 if (prow == ocur.row)
339 screen.cur.row = q - (total_rows - nrow);
340
341 line_t &pline = old_buf [prow];
342
343 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
344
345 assert (len);
346 assert (pline.t);
347
348 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
349 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
350
351 lofs += len;
352 qcol += len;
353 }
354 }
355
356 qline->l = llen ? MOD (llen - 1, ncol) + 1 : 0;
357#ifdef DEBUG_STRICT //TODO//FIXME//TEMPORARY
358 if (qline->l < 0)
359 {
360 fprintf (stderr, "ERROR, PLEASE REPORT to rxvt-unicode@plan9.de: qline->l %d = llen %d < ncol %d ? %d : MOD %d\n", qline->l,llen,ncol,llen,MOD (llen - 1, ncol) + 1);//D
361 qline->l = 0;
362 }
363#endif
364 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE);
297 } 365 }
366 while (p != pend && q > 0);
298 367
299 int qlines = max (0, (llen - 1) / ncol) + 1; 368 term_start = total_rows - nrow;
369 nsaved = term_start - q;
370
371 // make sure all terminal lines exist
372 while (nsaved < 0)
373 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE);
300 374
301 // drop partial lines completely 375 }
302 if (q < qlines) 376 else
303 break; 377 {
304 378 // if no scrollback exists (yet), wing, instead of wrap
305 q -= qlines; 379
306 380 for (int row = min (nrow, prev_nrow); row--; )
307 int lofs = 0;
308 line_t *qline;
309
310 // re-assemble the full line by destination lines
311 for (int qrow = q; qlines--; qrow++)
312 { 381 {
313 qline = row_buf + qrow;
314 lalloc (*qline);
315 qline->set_is_longer ();
316
317 int qcol = 0;
318
319 // fill a single destination line
320 while (lofs < llen && qcol < ncol)
321 {
322 int prow = lofs / prev_ncol;
323 int pcol = lofs % prev_ncol;
324
325 line_t &pline = old_buf [MOD (p + prow, prev_total_rows)]; 382 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)];
383 line_t &qline = row_buf [row];
326 384
327 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 385 qline = pline;
328 386 lresize (qline);
329 assert (len);
330 assert (pline.t);
331
332 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
333 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
334
335 lofs += len;
336 qcol += len;
337 }
338 } 387 }
339 388
340 qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1; 389 for (int row = prev_nrow; row < nrow; row++)
341 scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); 390 {
391 row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE);
342 } 392 }
343 393
344 term_start = total_rows - nrow;
345 view_start = 0; 394 term_start = 0;
346 nsaved = term_start - q; 395 }
347 396
348 // make sure all terminal lines exist 397#ifdef DEBUG_STRICT //TODO: remove
349 while (nsaved < 0)
350 scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE);
351
352 for (int i = -nsaved; i < nrow; i++) 398 for (int i = -nsaved; i < nrow; i++)
353 assert (ROW (i).t);//D 399 assert (ROW (i).t);
400#endif
354 401
355 free (old_buf); 402 free (old_buf);
356 delete old_ta; 403 delete old_ta;
357 delete old_ra; 404 delete old_ra;
358 405
359 min_it (screen.cur.row, nrow - 1); 406 clamp_it (screen.cur.row, 0, nrow - 1);
360 min_it (screen.cur.col, ncol - 1); 407 clamp_it (screen.cur.col, 0, ncol - 1);
361 408
362 if (tabs) 409 if (tabs)
363 free (tabs); 410 free (tabs);
364 } 411 }
365 412
580 { 627 {
581 selection.beg.row -= count; 628 selection.beg.row -= count;
582 selection.end.row -= count; 629 selection.end.row -= count;
583 selection.mark.row -= count; 630 selection.mark.row -= count;
584 631
585 selection_check (0); 632 if (selection.beg.row < -nsaved
633 || selection.end.row < -nsaved
634 || selection.mark.row < -nsaved)
635 {
636 CLEAR_ALL_SELECTION ();
637 selection.op = SELECTION_CLEAR;
638 }
586 } 639 }
587 640
588 for (int i = count; i--; ) 641 for (int i = count; i--; )
642 {
643 ROW(row2 - i).l = 0;
589 scr_blank_screen_mem (ROW(row2 - i), rstyle); 644 scr_blank_screen_mem (ROW(row2 - i), rstyle);
645 }
590 646
591 if ((options & Opt_scrollWithBuffer) 647 if ((options & Opt_scrollWithBuffer)
592 && view_start != 0 648 && view_start != 0
593 && view_start != saveLines) 649 && view_start != saveLines)
594 scr_page (UP, count); 650 scr_page (UP, count);
595 } 651 }
596 else 652 else
597 { 653 {
598 if (selection.op && current_screen == selection.screen) 654 if (selection.op && current_screen == selection.screen)
599 { 655 {
600 int i = selection.beg.row; 656 if ((selection.beg.row < row1 && selection.end.row > row1)
601 int j = selection.end.row; 657 || (selection.beg.row < row2 && selection.end.row > row2)
602
603 if ((i < row1 && j > row1)
604 || (i < row2 && j > row2)
605 || (i - count < row1 && i >= row1) 658 || (selection.beg.row - count < row1 && selection.beg.row >= row1)
606 || (i - count > row2 && i <= row2) 659 || (selection.beg.row - count > row2 && selection.beg.row <= row2)
607 || (j - count < row1 && j >= row1) 660 || (selection.end.row - count < row1 && selection.end.row >= row1)
608 || (j - count > row2 && j <= row2)) 661 || (selection.end.row - count > row2 && selection.end.row <= row2))
609 { 662 {
610 CLEAR_ALL_SELECTION (); 663 CLEAR_ALL_SELECTION ();
611 selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ 664 selection.op = SELECTION_CLEAR;
612 } 665 }
613 else if (j >= row1 && j <= row2) 666 else if (selection.end.row >= row1 && selection.end.row <= row2)
614 { 667 {
615 /* move selected region too */ 668 /* move selected region too */
616 selection.beg.row -= count; 669 selection.beg.row -= count;
617 selection.end.row -= count; 670 selection.end.row -= count;
618 selection.mark.row -= count; 671 selection.mark.row -= count;
653 if (len <= 0) /* sanity */ 706 if (len <= 0) /* sanity */
654 return; 707 return;
655 708
656 unsigned char checksel; 709 unsigned char checksel;
657 unicode_t c; 710 unicode_t c;
658 int row, last_col; 711 int last_col;
659 const unicode_t *strend = str + len; 712 const unicode_t *strend = str + len;
660 713
661 want_refresh = 1; 714 want_refresh = 1;
662 ZERO_SCROLLBACK (); 715 ZERO_SCROLLBACK ();
663 last_col = ncol; 716 last_col = ncol;
678#ifdef DEBUG_STRICT 731#ifdef DEBUG_STRICT
679 assert (screen.cur.col < last_col); 732 assert (screen.cur.col < last_col);
680 assert (screen.cur.row < nrow 733 assert (screen.cur.row < nrow
681 && screen.cur.row >= -nsaved); 734 && screen.cur.row >= -nsaved);
682#endif 735#endif
683 row = screen.cur.row; 736 int row = screen.cur.row;
684 737
685 checksel = selection.op && current_screen == selection.screen ? 1 : 0; 738 checksel = selection.op && current_screen == selection.screen ? 1 : 0;
686 739
687 line_t *line = &ROW(row); 740 line_t *line = &ROW(row);
688 741
690 { 743 {
691 c = *str++; 744 c = *str++;
692 745
693 if (c < 0x20) 746 if (c < 0x20)
694 if (c == C0_LF) 747 if (c == C0_LF)
695 { 748 {
696 if (!line->is_longer ()) /* XXX: think about this */ 749 if (!line->is_longer ()) /* XXX: think about this */
697 max_it (line->l, screen.cur.col); 750 max_it (line->l, screen.cur.col);
698 751
699 screen.flags &= ~Screen_WrapNext; 752 screen.flags &= ~Screen_WrapNext;
700 753
945 998
946 if (count == 0) 999 if (count == 0)
947 return; 1000 return;
948 else if (count > 0) 1001 else if (count > 0)
949 { 1002 {
950 int row = screen.cur.row;
951
952 line_t &l = ROW(row); 1003 line_t &l = ROW(screen.cur.row);
953 rend_t base_rend = l.r[i]; 1004 rend_t base_rend = l.r[i];
954 ht &= l.t[i] == ' '; 1005 ht &= l.t[i] == ' ';
955 1006
956 for (; ++i < ncol; ) 1007 for (; ++i < ncol; )
957 if (tabs[i]) 1008 if (tabs[i])
1032 */ 1083 */
1033#if ENABLE_FRILLS 1084#if ENABLE_FRILLS
1034void 1085void
1035rxvt_term::scr_forwardindex () 1086rxvt_term::scr_forwardindex ()
1036{ 1087{
1037 int row;
1038
1039 if (screen.cur.col < ncol - 1) 1088 if (screen.cur.col < ncol - 1)
1040 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); 1089 scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE);
1041 else 1090 else
1042 { 1091 {
1043 row = screen.cur.row;
1044
1045 if (ROW(row).is_longer ()) //TODO//FIXME//LEN 1092 if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN
1046 ROW(row).l = ncol; 1093 ROW(screen.cur.row).l = ncol;
1047 1094
1048 scr_gotorc (0, 0, R_RELATIVE); 1095 scr_gotorc (0, 0, R_RELATIVE);
1049 scr_insdel_chars (1, DELETE); 1096 scr_insdel_chars (1, DELETE);
1050 scr_gotorc (0, ncol - 1, R_RELATIVE); 1097 scr_gotorc (0, ncol - 1, R_RELATIVE);
1051 } 1098 }
1134 * XTERM_SEQ: Clear whole line : ESC [ 2 K 1181 * XTERM_SEQ: Clear whole line : ESC [ 2 K
1135 */ 1182 */
1136void 1183void
1137rxvt_term::scr_erase_line (int mode) 1184rxvt_term::scr_erase_line (int mode)
1138{ 1185{
1139 unsigned int row, col, num; 1186 unsigned int col, num;
1140 1187
1141 want_refresh = 1; 1188 want_refresh = 1;
1142 ZERO_SCROLLBACK (); 1189 ZERO_SCROLLBACK ();
1143 1190
1144 selection_check (1); 1191 selection_check (1);
1145 1192
1146 row = screen.cur.row; 1193 line_t &line = ROW(screen.cur.row);
1147 1194
1148 switch (mode) 1195 switch (mode)
1149 { 1196 {
1150 case 0: /* erase to end of line */ 1197 case 0: /* erase to end of line */
1151 col = screen.cur.col; 1198 col = screen.cur.col;
1152 num = ncol - col; 1199 num = ncol - col;
1153 min_it (ROW(row).l, col); 1200 min_it (line.l, col);
1154 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) 1201 if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)
1155 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) 1202 || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur))
1156 CLEAR_SELECTION (); 1203 CLEAR_SELECTION ();
1157 break; 1204 break;
1158 case 1: /* erase to beginning of line */ 1205 case 1: /* erase to beginning of line */
1163 CLEAR_SELECTION (); 1210 CLEAR_SELECTION ();
1164 break; 1211 break;
1165 case 2: /* erase whole line */ 1212 case 2: /* erase whole line */
1166 col = 0; 1213 col = 0;
1167 num = ncol; 1214 num = ncol;
1168 ROW(row).l = 0; 1215 line.l = 0;
1169 if (selection.beg.row <= screen.cur.row 1216 if (selection.beg.row <= screen.cur.row
1170 && selection.end.row >= screen.cur.row) 1217 && selection.end.row >= screen.cur.row)
1171 CLEAR_SELECTION (); 1218 CLEAR_SELECTION ();
1172 break; 1219 break;
1173 default: 1220 default:
1174 return; 1221 return;
1175 } 1222 }
1176 1223
1177 scr_blank_line (ROW(row), col, num, rstyle); 1224 scr_blank_line (line, col, num, rstyle);
1178} 1225}
1179 1226
1180/* ------------------------------------------------------------------------- */ 1227/* ------------------------------------------------------------------------- */
1181/* 1228/*
1182 * Erase part of whole of the screen 1229 * Erase part of whole of the screen
1246 XChangeGC (display->display, gc, GCForeground, &gcvalue); 1293 XChangeGC (display->display, gc, GCForeground, &gcvalue);
1247 } 1294 }
1248 1295
1249 for (; num--; row++) 1296 for (; num--; row++)
1250 { 1297 {
1298 ROW (row).l = 0;
1251 scr_blank_screen_mem (ROW (row), rstyle); 1299 scr_blank_screen_mem (ROW (row), rstyle);
1252 ROW (row).l = 0;
1253 scr_blank_line (drawn_buf [row], 0, ncol, ren); 1300 scr_blank_line (drawn_buf [row], 0, ncol, ren);
1254 } 1301 }
1255} 1302}
1256 1303
1257#if ENABLE_FRILLS 1304#if ENABLE_FRILLS
2143 * Determine the attributes for the string 2190 * Determine the attributes for the string
2144 */ 2191 */
2145 int fore = GET_FGCOLOR (rend); // desired foreground 2192 int fore = GET_FGCOLOR (rend); // desired foreground
2146 int back = GET_BGCOLOR (rend); // desired background 2193 int back = GET_BGCOLOR (rend); // desired background
2147 2194
2148 // only do special processing if any attributes are set, which is rare 2195 // only do special processing if any attributes are set, which is unlikely
2149 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2196 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful))
2150 { 2197 {
2151#if ENABLE_STYLES 2198#if ENABLE_STYLES
2152 // force redraw after "careful" characters to avoid pixel droppings 2199 // force redraw after "careful" characters to avoid pixel droppings
2153 if (srp[col] & RS_Careful && col < ncol - 1 && 0) 2200 if (srp[col] & RS_Careful && col < ncol - 1 && 0)
2415 row = selection.beg.row; 2462 row = selection.beg.row;
2416 } 2463 }
2417 else 2464 else
2418 { 2465 {
2419 col = 0; 2466 col = 0;
2420 row = view_start; 2467 row = -view_start;
2421 } 2468 }
2422 2469
2423 for (; row < min (selection.end.row, view_end); row++, col = 0) 2470 for (; row < min (selection.end.row, view_end); row++, col = 0)
2424 for (rend_t *srp = ROW(row).r; col < ncol; col++) 2471 for (rend_t *srp = ROW(row).r; col < ncol; col++)
2425 srp[col] ^= RS_RVid; 2472 srp[col] ^= RS_RVid;
3629 for (int y = ov_h; y--; ) 3676 for (int y = ov_h; y--; )
3630 { 3677 {
3631 text_t *t1 = ov_text[y]; 3678 text_t *t1 = ov_text[y];
3632 rend_t *r1 = ov_rend[y]; 3679 rend_t *r1 = ov_rend[y];
3633 3680
3634 text_t *t2 = ROW(y - view_start).t + ov_x; 3681 text_t *t2 = ROW(y + ov_y - view_start).t + ov_x;
3635 rend_t *r2 = ROW(y - view_start).r + ov_x; 3682 rend_t *r2 = ROW(y + ov_y - view_start).r + ov_x;
3636 3683
3637 for (int x = ov_w; x--; ) 3684 for (int x = ov_w; x--; )
3638 { 3685 {
3639 text_t t = *t1; *t1++ = *t2; *t2++ = t; 3686 text_t t = *t1; *t1++ = *t2; *t2++ = t;
3640 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t)); 3687 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines