… | |
… | |
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 < ncol ? llen : MOD (llen - 1, ncol) + 1; |
|
|
357 | printf ("qline->l %d = llen %d < ncol %d ? %d : MOD %d\n", qline->l,llen,ncol,llen,MOD (llen - 1, ncol) + 1);//D |
|
|
358 | scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); |
297 | } |
359 | } |
|
|
360 | while (p != pend && q > 0); |
298 | |
361 | |
299 | int qlines = max (0, (llen - 1) / ncol) + 1; |
362 | term_start = total_rows - nrow; |
|
|
363 | nsaved = term_start - q; |
|
|
364 | |
|
|
365 | // make sure all terminal lines exist |
|
|
366 | while (nsaved < 0) |
|
|
367 | scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); |
300 | |
368 | |
301 | // drop partial lines completely |
369 | } |
302 | if (q < qlines) |
370 | else |
303 | break; |
371 | { |
304 | |
372 | // if no scrollback exists (yet), wing, instead of wrap |
305 | q -= qlines; |
373 | |
306 | |
374 | 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 | { |
375 | { |
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)]; |
376 | line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)]; |
|
|
377 | line_t &qline = row_buf [row]; |
326 | |
378 | |
327 | int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); |
379 | qline = pline; |
328 | |
380 | 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 | } |
381 | } |
339 | |
382 | |
340 | qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1; |
383 | for (int row = prev_nrow; row < nrow; row++) |
341 | scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); |
384 | { |
|
|
385 | row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE); |
342 | } |
386 | } |
343 | |
387 | |
344 | term_start = total_rows - nrow; |
|
|
345 | view_start = 0; |
388 | term_start = 0; |
346 | nsaved = term_start - q; |
389 | } |
347 | |
390 | |
348 | // make sure all terminal lines exist |
391 | #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++) |
392 | for (int i = -nsaved; i < nrow; i++) |
353 | assert (ROW (i).t);//D |
393 | assert (ROW (i).t); |
|
|
394 | #endif |
354 | |
395 | |
355 | free (old_buf); |
396 | free (old_buf); |
356 | delete old_ta; |
397 | delete old_ta; |
357 | delete old_ra; |
398 | delete old_ra; |
358 | |
399 | |
359 | min_it (screen.cur.row, nrow - 1); |
400 | clamp_it (screen.cur.row, 0, nrow - 1); |
360 | min_it (screen.cur.col, ncol - 1); |
401 | clamp_it (screen.cur.col, 0, ncol - 1); |
361 | |
402 | |
362 | if (tabs) |
403 | if (tabs) |
363 | free (tabs); |
404 | free (tabs); |
364 | } |
405 | } |
365 | |
406 | |
… | |
… | |
580 | { |
621 | { |
581 | selection.beg.row -= count; |
622 | selection.beg.row -= count; |
582 | selection.end.row -= count; |
623 | selection.end.row -= count; |
583 | selection.mark.row -= count; |
624 | selection.mark.row -= count; |
584 | |
625 | |
585 | selection_check (0); |
626 | if (selection.beg.row < -nsaved |
|
|
627 | || selection.end.row < -nsaved |
|
|
628 | || selection.mark.row < -nsaved) |
|
|
629 | { |
|
|
630 | CLEAR_ALL_SELECTION (); |
|
|
631 | selection.op = SELECTION_CLEAR; |
|
|
632 | } |
586 | } |
633 | } |
587 | |
634 | |
588 | for (int i = count; i--; ) |
635 | for (int i = count; i--; ) |
|
|
636 | { |
|
|
637 | ROW(row2 - i).l = 0; |
589 | scr_blank_screen_mem (ROW(row2 - i), rstyle); |
638 | scr_blank_screen_mem (ROW(row2 - i), rstyle); |
|
|
639 | } |
590 | |
640 | |
591 | if ((options & Opt_scrollWithBuffer) |
641 | if ((options & Opt_scrollWithBuffer) |
592 | && view_start != 0 |
642 | && view_start != 0 |
593 | && view_start != saveLines) |
643 | && view_start != saveLines) |
594 | scr_page (UP, count); |
644 | scr_page (UP, count); |
595 | } |
645 | } |
596 | else |
646 | else |
597 | { |
647 | { |
598 | if (selection.op && current_screen == selection.screen) |
648 | if (selection.op && current_screen == selection.screen) |
599 | { |
649 | { |
600 | int i = selection.beg.row; |
650 | if ((selection.beg.row < row1 && selection.end.row > row1) |
601 | int j = selection.end.row; |
651 | || (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) |
652 | || (selection.beg.row - count < row1 && selection.beg.row >= row1) |
606 | || (i - count > row2 && i <= row2) |
653 | || (selection.beg.row - count > row2 && selection.beg.row <= row2) |
607 | || (j - count < row1 && j >= row1) |
654 | || (selection.end.row - count < row1 && selection.end.row >= row1) |
608 | || (j - count > row2 && j <= row2)) |
655 | || (selection.end.row - count > row2 && selection.end.row <= row2)) |
609 | { |
656 | { |
610 | CLEAR_ALL_SELECTION (); |
657 | CLEAR_ALL_SELECTION (); |
611 | selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ |
658 | selection.op = SELECTION_CLEAR; |
612 | } |
659 | } |
613 | else if (j >= row1 && j <= row2) |
660 | else if (selection.end.row >= row1 && selection.end.row <= row2) |
614 | { |
661 | { |
615 | /* move selected region too */ |
662 | /* move selected region too */ |
616 | selection.beg.row -= count; |
663 | selection.beg.row -= count; |
617 | selection.end.row -= count; |
664 | selection.end.row -= count; |
618 | selection.mark.row -= count; |
665 | selection.mark.row -= count; |
… | |
… | |
653 | if (len <= 0) /* sanity */ |
700 | if (len <= 0) /* sanity */ |
654 | return; |
701 | return; |
655 | |
702 | |
656 | unsigned char checksel; |
703 | unsigned char checksel; |
657 | unicode_t c; |
704 | unicode_t c; |
658 | int row, last_col; |
705 | int last_col; |
659 | const unicode_t *strend = str + len; |
706 | const unicode_t *strend = str + len; |
660 | |
707 | |
661 | want_refresh = 1; |
708 | want_refresh = 1; |
662 | ZERO_SCROLLBACK (); |
709 | ZERO_SCROLLBACK (); |
663 | last_col = ncol; |
710 | last_col = ncol; |
… | |
… | |
678 | #ifdef DEBUG_STRICT |
725 | #ifdef DEBUG_STRICT |
679 | assert (screen.cur.col < last_col); |
726 | assert (screen.cur.col < last_col); |
680 | assert (screen.cur.row < nrow |
727 | assert (screen.cur.row < nrow |
681 | && screen.cur.row >= -nsaved); |
728 | && screen.cur.row >= -nsaved); |
682 | #endif |
729 | #endif |
683 | row = screen.cur.row; |
730 | int row = screen.cur.row; |
684 | |
731 | |
685 | checksel = selection.op && current_screen == selection.screen ? 1 : 0; |
732 | checksel = selection.op && current_screen == selection.screen ? 1 : 0; |
686 | |
733 | |
687 | line_t *line = &ROW(row); |
734 | line_t *line = &ROW(row); |
688 | |
735 | |
… | |
… | |
690 | { |
737 | { |
691 | c = *str++; |
738 | c = *str++; |
692 | |
739 | |
693 | if (c < 0x20) |
740 | if (c < 0x20) |
694 | if (c == C0_LF) |
741 | if (c == C0_LF) |
695 | { |
742 | { |
696 | if (!line->is_longer ()) /* XXX: think about this */ |
743 | if (!line->is_longer ()) /* XXX: think about this */ |
697 | max_it (line->l, screen.cur.col); |
744 | max_it (line->l, screen.cur.col); |
698 | |
745 | |
699 | screen.flags &= ~Screen_WrapNext; |
746 | screen.flags &= ~Screen_WrapNext; |
700 | |
747 | |
… | |
… | |
945 | |
992 | |
946 | if (count == 0) |
993 | if (count == 0) |
947 | return; |
994 | return; |
948 | else if (count > 0) |
995 | else if (count > 0) |
949 | { |
996 | { |
950 | int row = screen.cur.row; |
|
|
951 | |
|
|
952 | line_t &l = ROW(row); |
997 | line_t &l = ROW(screen.cur.row); |
953 | rend_t base_rend = l.r[i]; |
998 | rend_t base_rend = l.r[i]; |
954 | ht &= l.t[i] == ' '; |
999 | ht &= l.t[i] == ' '; |
955 | |
1000 | |
956 | for (; ++i < ncol; ) |
1001 | for (; ++i < ncol; ) |
957 | if (tabs[i]) |
1002 | if (tabs[i]) |
… | |
… | |
1032 | */ |
1077 | */ |
1033 | #if ENABLE_FRILLS |
1078 | #if ENABLE_FRILLS |
1034 | void |
1079 | void |
1035 | rxvt_term::scr_forwardindex () |
1080 | rxvt_term::scr_forwardindex () |
1036 | { |
1081 | { |
1037 | int row; |
|
|
1038 | |
|
|
1039 | if (screen.cur.col < ncol - 1) |
1082 | if (screen.cur.col < ncol - 1) |
1040 | scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); |
1083 | scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); |
1041 | else |
1084 | else |
1042 | { |
1085 | { |
1043 | row = screen.cur.row; |
|
|
1044 | |
|
|
1045 | if (ROW(row).is_longer ()) //TODO//FIXME//LEN |
1086 | if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN |
1046 | ROW(row).l = ncol; |
1087 | ROW(screen.cur.row).l = ncol; |
1047 | |
1088 | |
1048 | scr_gotorc (0, 0, R_RELATIVE); |
1089 | scr_gotorc (0, 0, R_RELATIVE); |
1049 | scr_insdel_chars (1, DELETE); |
1090 | scr_insdel_chars (1, DELETE); |
1050 | scr_gotorc (0, ncol - 1, R_RELATIVE); |
1091 | scr_gotorc (0, ncol - 1, R_RELATIVE); |
1051 | } |
1092 | } |
… | |
… | |
1134 | * XTERM_SEQ: Clear whole line : ESC [ 2 K |
1175 | * XTERM_SEQ: Clear whole line : ESC [ 2 K |
1135 | */ |
1176 | */ |
1136 | void |
1177 | void |
1137 | rxvt_term::scr_erase_line (int mode) |
1178 | rxvt_term::scr_erase_line (int mode) |
1138 | { |
1179 | { |
1139 | unsigned int row, col, num; |
1180 | unsigned int col, num; |
1140 | |
1181 | |
1141 | want_refresh = 1; |
1182 | want_refresh = 1; |
1142 | ZERO_SCROLLBACK (); |
1183 | ZERO_SCROLLBACK (); |
1143 | |
1184 | |
1144 | selection_check (1); |
1185 | selection_check (1); |
1145 | |
1186 | |
1146 | row = screen.cur.row; |
1187 | line_t &line = ROW(screen.cur.row); |
1147 | |
1188 | |
1148 | switch (mode) |
1189 | switch (mode) |
1149 | { |
1190 | { |
1150 | case 0: /* erase to end of line */ |
1191 | case 0: /* erase to end of line */ |
1151 | col = screen.cur.col; |
1192 | col = screen.cur.col; |
1152 | num = ncol - col; |
1193 | num = ncol - col; |
1153 | min_it (ROW(row).l, col); |
1194 | min_it (line.l, col); |
1154 | if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) |
1195 | if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) |
1155 | || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) |
1196 | || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) |
1156 | CLEAR_SELECTION (); |
1197 | CLEAR_SELECTION (); |
1157 | break; |
1198 | break; |
1158 | case 1: /* erase to beginning of line */ |
1199 | case 1: /* erase to beginning of line */ |
… | |
… | |
1163 | CLEAR_SELECTION (); |
1204 | CLEAR_SELECTION (); |
1164 | break; |
1205 | break; |
1165 | case 2: /* erase whole line */ |
1206 | case 2: /* erase whole line */ |
1166 | col = 0; |
1207 | col = 0; |
1167 | num = ncol; |
1208 | num = ncol; |
1168 | ROW(row).l = 0; |
1209 | line.l = 0; |
1169 | if (selection.beg.row <= screen.cur.row |
1210 | if (selection.beg.row <= screen.cur.row |
1170 | && selection.end.row >= screen.cur.row) |
1211 | && selection.end.row >= screen.cur.row) |
1171 | CLEAR_SELECTION (); |
1212 | CLEAR_SELECTION (); |
1172 | break; |
1213 | break; |
1173 | default: |
1214 | default: |
1174 | return; |
1215 | return; |
1175 | } |
1216 | } |
1176 | |
1217 | |
1177 | scr_blank_line (ROW(row), col, num, rstyle); |
1218 | scr_blank_line (line, col, num, rstyle); |
1178 | } |
1219 | } |
1179 | |
1220 | |
1180 | /* ------------------------------------------------------------------------- */ |
1221 | /* ------------------------------------------------------------------------- */ |
1181 | /* |
1222 | /* |
1182 | * Erase part of whole of the screen |
1223 | * Erase part of whole of the screen |
… | |
… | |
1246 | XChangeGC (display->display, gc, GCForeground, &gcvalue); |
1287 | XChangeGC (display->display, gc, GCForeground, &gcvalue); |
1247 | } |
1288 | } |
1248 | |
1289 | |
1249 | for (; num--; row++) |
1290 | for (; num--; row++) |
1250 | { |
1291 | { |
|
|
1292 | ROW (row).l = 0; |
1251 | scr_blank_screen_mem (ROW (row), rstyle); |
1293 | scr_blank_screen_mem (ROW (row), rstyle); |
1252 | ROW (row).l = 0; |
|
|
1253 | scr_blank_line (drawn_buf [row], 0, ncol, ren); |
1294 | scr_blank_line (drawn_buf [row], 0, ncol, ren); |
1254 | } |
1295 | } |
1255 | } |
1296 | } |
1256 | |
1297 | |
1257 | #if ENABLE_FRILLS |
1298 | #if ENABLE_FRILLS |
… | |
… | |
2415 | row = selection.beg.row; |
2456 | row = selection.beg.row; |
2416 | } |
2457 | } |
2417 | else |
2458 | else |
2418 | { |
2459 | { |
2419 | col = 0; |
2460 | col = 0; |
2420 | row = view_start; |
2461 | row = -view_start; |
2421 | } |
2462 | } |
2422 | |
2463 | |
2423 | for (; row < min (selection.end.row, view_end); row++, col = 0) |
2464 | for (; row < min (selection.end.row, view_end); row++, col = 0) |
2424 | for (rend_t *srp = ROW(row).r; col < ncol; col++) |
2465 | for (rend_t *srp = ROW(row).r; col < ncol; col++) |
2425 | srp[col] ^= RS_RVid; |
2466 | srp[col] ^= RS_RVid; |