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.307 by root, Fri Jun 27 00:44:32 2008 UTC vs.
Revision 1.316 by root, Tue Nov 4 15:02:35 2008 UTC

132 132
133 l.l = 0; 133 l.l = 0;
134 l.f = 0; 134 l.f = 0;
135} 135}
136 136
137// nuke a single wide character at the given column
138void
139rxvt_term::scr_kill_char (line_t &l, int col) const NOTHROW
140{
141 // find begin
142 while (col > 0 && l.t[col] == NOCHAR)
143 col--;
144
145 rend_t rend = l.r[col] & ~RS_baseattrMask;
146 rend = SET_FONT (rend, FONTSET (rend)->find_font (' '));
147
148 // found start, nuke
149 do {
150 l.t[col] = ' ';
151 l.r[col] = rend;
152 col++;
153 } while (col < ncol && l.t[col] == NOCHAR);
154}
155
137/* ------------------------------------------------------------------------- * 156/* ------------------------------------------------------------------------- *
138 * SCREEN INITIALISATION * 157 * SCREEN INITIALISATION *
139 * ------------------------------------------------------------------------- */ 158 * ------------------------------------------------------------------------- */
140 159
141void 160void
771 790
772 while (str < strend) 791 while (str < strend)
773 { 792 {
774 c = (unicode_t)*str++; // convert to rxvt-unicodes representation 793 c = (unicode_t)*str++; // convert to rxvt-unicodes representation
775 794
776 if (c < 0x20) 795 if (expect_false (c < 0x20))
777 if (c == C0_LF) 796 if (c == C0_LF)
778 { 797 {
779 max_it (line->l, screen.cur.col); 798 max_it (line->l, screen.cur.col);
780 799
781 screen.flags &= ~Screen_WrapNext; 800 screen.flags &= ~Screen_WrapNext;
800 { 819 {
801 scr_tab (1, true); 820 scr_tab (1, true);
802 continue; 821 continue;
803 } 822 }
804 823
824 if (expect_false (
805 if (checksel /* see if we're writing within selection */ 825 checksel /* see if we're writing within selection */
806 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg) 826 && !ROWCOL_IS_BEFORE (screen.cur, selection.beg)
807 && ROWCOL_IS_BEFORE (screen.cur, selection.end)) 827 && ROWCOL_IS_BEFORE (screen.cur, selection.end)
828 ))
808 { 829 {
809 checksel = 0; 830 checksel = 0;
810 /* 831 /*
811 * If we wrote anywhere in the selected area, kill the selection 832 * If we wrote anywhere in the selected area, kill the selection
812 * XXX: should we kill the mark too? Possibly, but maybe that 833 * XXX: should we kill the mark too? Possibly, but maybe that
813 * should be a similar check. 834 * should be a similar check.
814 */ 835 */
815 CLEAR_SELECTION (); 836 CLEAR_SELECTION ();
816 } 837 }
817 838
818 if (screen.flags & Screen_WrapNext) 839 if (expect_false (screen.flags & Screen_WrapNext))
819 { 840 {
820 scr_do_wrap (); 841 scr_do_wrap ();
821 842
822 line->l = ncol; 843 line->l = ncol;
823 line->is_longer (1); 844 line->is_longer (1);
825 row = screen.cur.row; 846 row = screen.cur.row;
826 line = &ROW(row); /* _must_ refresh */ 847 line = &ROW(row); /* _must_ refresh */
827 } 848 }
828 849
829 // some utf-8 decoders "decode" surrogate characters: let's fix this. 850 // some utf-8 decoders "decode" surrogate characters: let's fix this.
830 if (IN_RANGE_INC (c, 0xd800, 0xdfff)) 851 if (expect_false (IN_RANGE_INC (c, 0xd800, 0xdfff)))
831 c = 0xfffd; 852 c = 0xfffd;
832 853
833 // rely on wcwidth to tell us the character width, do wcwidth before 854 // rely on wcwidth to tell us the character width, do wcwidth before
834 // further replacements, as wcwidth might return -1 for the line 855 // further replacements, as wcwidth might return -1 for the line
835 // drawing characters below as they might be invalid in the current 856 // drawing characters below as they might be invalid in the current
836 // locale. 857 // locale.
837 int width = WCWIDTH (c); 858 int width = WCWIDTH (c);
838 859
839 if (charsets [screen.charset] == '0') // DEC SPECIAL 860 if (expect_false (charsets [screen.charset] == '0')) // DEC SPECIAL
840 { 861 {
841 // vt100 special graphics and line drawing 862 // vt100 special graphics and line drawing
842 // 5f-7e standard vt100 863 // 5f-7e standard vt100
843 // 40-5e rxvt extension for extra curses acs chars 864 // 40-5e rxvt extension for extra curses acs chars
844 static uint16_t vt100_0[62] = { // 41 .. 7e 865 static uint16_t vt100_0[62] = { // 41 .. 7e
857 c = vt100_0[c - 0x41]; 878 c = vt100_0[c - 0x41];
858 width = 1; // vt100 line drawing characters are always single-width 879 width = 1; // vt100 line drawing characters are always single-width
859 } 880 }
860 } 881 }
861 882
862 if (screen.flags & Screen_Insert) 883 if (expect_false (screen.flags & Screen_Insert))
863 scr_insdel_chars (width, INSERT); 884 scr_insdel_chars (width, INSERT);
864 885
865 if (width != 0) 886 if (width != 0)
866 { 887 {
867#if !UNICODE_3 888#if !UNICODE_3
873 c = 0xfffd; 894 c = 0xfffd;
874# endif 895# endif
875#endif 896#endif
876 897
877 // nuke the character at this position, if required 898 // nuke the character at this position, if required
899 if (expect_false (
878 if (line->t[screen.cur.col] == NOCHAR 900 line->t[screen.cur.col] == NOCHAR
879 || (screen.cur.col < ncol - 1 901 || (screen.cur.col < ncol - 1
880 && line->t[screen.cur.col + 1] == NOCHAR)) 902 && line->t[screen.cur.col + 1] == NOCHAR)
881 { 903 ))
882 int col = screen.cur.col; 904 scr_kill_char (*line, screen.cur.col);
883
884 // find begin
885 while (col > 0 && line->t[col] == NOCHAR)
886 col--;
887
888 rend_t rend = SET_FONT (line->r[col], FONTSET (line->r[col])->find_font (' '));
889
890 // found begin, nuke
891 do {
892 line->t[col] = ' ';
893 line->r[col] = rend;
894 col++;
895 } while (col < ncol && line->t[col] == NOCHAR);
896 }
897 905
898 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c)); 906 rend_t rend = SET_FONT (rstyle, FONTSET (rstyle)->find_font (c));
899 907
900 // if the character doesn't fit into the remaining columns... 908 // if the character doesn't fit into the remaining columns...
901 if (screen.cur.col > ncol - width && ncol >= width) 909 if (expect_false (screen.cur.col > ncol - width && ncol >= width))
902 { 910 {
903 // ...output spaces 911 // ...output spaces
904 c = ' '; 912 c = ' ';
905 // and try the same character next loop iteration 913 // and try the same character next loop iteration
906 --str; 914 --str;
911 do 919 do
912 { 920 {
913 line->t[screen.cur.col] = c; 921 line->t[screen.cur.col] = c;
914 line->r[screen.cur.col] = rend; 922 line->r[screen.cur.col] = rend;
915 923
916 if (screen.cur.col < ncol - 1) 924 if (expect_true (screen.cur.col < ncol - 1))
917 screen.cur.col++; 925 screen.cur.col++;
918 else 926 else
919 { 927 {
920 line->l = ncol; 928 line->l = ncol;
921 if (screen.flags & Screen_Autowrap) 929 if (screen.flags & Screen_Autowrap)
923 break; 931 break;
924 } 932 }
925 933
926 c = NOCHAR; 934 c = NOCHAR;
927 } 935 }
928 while (--width > 0); 936 while (expect_false (--width > 0));
929 937
930 // pad with spaces when overwriting wide character with smaller one 938 // pad with spaces when overwriting wide character with smaller one
931 if (!width) 939 if (expect_false (!width))
932 { 940 {
933 line->touch (); 941 line->touch ();
934 942
935 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++) 943 for (int c = screen.cur.col; c < ncol && line->t[c] == NOCHAR; c++)
936 { 944 {
937 line->t[c] = ' '; 945 line->t[c] = ' ';
938 line->r[c] = rend; 946 line->r[c] = rend;
939 } 947 }
940 } 948 }
941 } 949 }
950#if ENABLE_COMBINING
942 else // width == 0 951 else // width == 0
943 { 952 {
944#if ENABLE_COMBINING 953 if (c != 0xfeff) // ignore BOM
945 // handle combining characters
946 // we just tag the accent on the previous on-screen character.
947 // this is arguably not correct, but also arguably not wrong.
948 // we don't handle double-width characters nicely yet.
949 line_t *linep;
950 text_t *tp;
951 rend_t *rp;
952
953 if (screen.cur.col > 0)
954 { 954 {
955 // handle combining characters
956 // we just tag the accent on the previous on-screen character.
957 // this is arguably not correct, but also arguably not wrong.
958 // we don't handle double-width characters nicely yet.
959 line_t *linep;
960 text_t *tp;
961 rend_t *rp;
962
963 if (screen.cur.col > 0)
964 {
955 linep = line; 965 linep = line;
956 tp = line->t + screen.cur.col - 1; 966 tp = line->t + screen.cur.col - 1;
957 rp = line->r + screen.cur.col - 1; 967 rp = line->r + screen.cur.col - 1;
968 }
969 else if (screen.cur.row > 0
970 && ROW(screen.cur.row - 1).is_longer ())
971 {
972 linep = &ROW(screen.cur.row - 1);
973 tp = line->t + ncol - 1;
974 rp = line->r + ncol - 1;
975 }
976 else
977 continue;
978
979 linep->touch ();
980
981 while (*tp == NOCHAR && tp > linep->t)
982 tp--, rp--;
983
984 // first try to find a precomposed character
985 unicode_t n = rxvt_compose (*tp, c);
986 if (n == NOCHAR)
987 n = rxvt_composite.compose (*tp, c);
988
989 *tp = n;
990 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
958 } 991 }
959 else if (screen.cur.row > 0
960 && ROW(screen.cur.row - 1).is_longer ())
961 {
962 linep = &ROW(screen.cur.row - 1);
963 tp = line->t + ncol - 1;
964 rp = line->r + ncol - 1;
965 } 992 }
966 else
967 continue;
968
969 linep->touch ();
970
971 while (*tp == NOCHAR && tp > linep->t)
972 tp--, rp--;
973
974 // first try to find a precomposed character
975 unicode_t n = rxvt_compose (*tp, c);
976 if (n == NOCHAR)
977 n = rxvt_composite.compose (*tp, c);
978
979 *tp = n;
980 *rp = SET_FONT (*rp, FONTSET (*rp)->find_font (*tp));
981#endif 993#endif
982 }
983 } 994 }
984 995
985 max_it (line->l, screen.cur.col); 996 max_it (line->l, screen.cur.col);
986 997
987#ifdef DEBUG_STRICT 998#ifdef DEBUG_STRICT
1435 * Insert/Delete <count> characters from the current position 1446 * Insert/Delete <count> characters from the current position
1436 */ 1447 */
1437void 1448void
1438rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW 1449rxvt_term::scr_insdel_chars (int count, int insdel) NOTHROW
1439{ 1450{
1440 int col, row;
1441 rend_t tr;
1442
1443 want_refresh = 1; 1451 want_refresh = 1;
1444 ZERO_SCROLLBACK (); 1452 ZERO_SCROLLBACK ();
1445 1453
1446 if (count <= 0) 1454 if (count <= 0)
1447 return; 1455 return;
1449 scr_do_wrap (); 1457 scr_do_wrap ();
1450 1458
1451 selection_check (1); 1459 selection_check (1);
1452 min_it (count, ncol - screen.cur.col); 1460 min_it (count, ncol - screen.cur.col);
1453 1461
1454 row = screen.cur.row; 1462 int row = screen.cur.row;
1455 1463
1456 line_t *line = &ROW(row); 1464 line_t *line = &ROW(row);
1457 1465
1458 line->touch (); 1466 line->touch ();
1459 line->is_longer (0); 1467 line->is_longer (0);
1460 1468
1469 // nuke wide spanning the start
1470 if (line->t[screen.cur.col] == NOCHAR)
1471 scr_kill_char (*line, screen.cur.col);
1472
1461 switch (insdel) 1473 switch (insdel)
1462 { 1474 {
1463 case INSERT: 1475 case INSERT:
1464 for (col = ncol - 1; (col - count) >= screen.cur.col; col--) 1476 line->l = min (line->l + count, ncol);
1477
1478 if (line->t[screen.cur.col] == NOCHAR)
1479 scr_kill_char (*line, screen.cur.col);
1480
1481 for (int col = ncol - 1; (col - count) >= screen.cur.col; col--)
1465 { 1482 {
1466 line->t[col] = line->t[col - count]; 1483 line->t[col] = line->t[col - count];
1467 line->r[col] = line->r[col - count]; 1484 line->r[col] = line->r[col - count];
1468 } 1485 }
1469
1470 line->l = min (line->l + count, ncol);
1471 1486
1472 if (selection.op && current_screen == selection.screen 1487 if (selection.op && current_screen == selection.screen
1473 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1488 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1474 { 1489 {
1475 if (selection.end.row != screen.cur.row 1490 if (selection.end.row != screen.cur.row
1490 case ERASE: 1505 case ERASE:
1491 screen.cur.col += count; /* don't worry if > ncol */ 1506 screen.cur.col += count; /* don't worry if > ncol */
1492 selection_check (1); 1507 selection_check (1);
1493 screen.cur.col -= count; 1508 screen.cur.col -= count;
1494 1509
1495 line->l = max (line->l - count, 0); 1510 // nuke wide char after the end
1511 if (screen.cur.col + count < ncol && line->t[screen.cur.col + count] == NOCHAR)
1512 scr_kill_char (*line, screen.cur.col + count);
1513
1496 scr_blank_line (*line, screen.cur.col, count, rstyle); 1514 scr_blank_line (*line, screen.cur.col, count, rstyle);
1497 break; 1515 break;
1498 1516
1499 case DELETE: 1517 case DELETE:
1500 tr = line->r[ncol - 1] & (RS_fgMask | RS_bgMask | RS_baseattrMask); 1518 line->l = max (line->l - count, 0);
1501 1519
1520 // nuke wide char spanning the end
1521 if (screen.cur.col + count < ncol && line->t[screen.cur.col + count] == NOCHAR)
1522 scr_kill_char (*line, screen.cur.col + count);
1523
1502 for (col = screen.cur.col; (col + count) < ncol; col++) 1524 for (int col = screen.cur.col; (col + count) < ncol; col++)
1503 { 1525 {
1504 line->t[col] = line->t[col + count]; 1526 line->t[col] = line->t[col + count];
1505 line->r[col] = line->r[col + count]; 1527 line->r[col] = line->r[col + count];
1506 } 1528 }
1507 1529
1508 line->l = max (line->l - count, 0);
1509 scr_blank_line (*line, ncol - count, count, tr); 1530 scr_blank_line (*line, ncol - count, count,
1531 line->r[ncol - 1] & (RS_fgMask | RS_bgMask | RS_baseattrMask));
1510 1532
1511 if (selection.op && current_screen == selection.screen 1533 if (selection.op && current_screen == selection.screen
1512 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur)) 1534 && ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur))
1513 { 1535 {
1514 if (selection.end.row != screen.cur.row 1536 if (selection.end.row != screen.cur.row
1892 XMapWindow (dpy, parent[0]); 1914 XMapWindow (dpy, parent[0]);
1893# endif 1915# endif
1894 1916
1895# if ENABLE_FRILLS 1917# if ENABLE_FRILLS
1896 if (option (Opt_urgentOnBell)) 1918 if (option (Opt_urgentOnBell))
1897 { 1919 set_urgency (1);
1898 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1899 {
1900 h->flags |= XUrgencyHint;
1901 XSetWMHints (dpy, parent[0], h);
1902 }
1903 }
1904# endif 1920# endif
1905 1921
1906 if (option (Opt_visualBell)) 1922 if (option (Opt_visualBell))
1907 { 1923 {
1908 rvideo_bell = true; 1924 rvideo_bell = true;
1921void 1937void
1922rxvt_term::scr_printscreen (int fullhist) NOTHROW 1938rxvt_term::scr_printscreen (int fullhist) NOTHROW
1923{ 1939{
1924#ifdef PRINTPIPE 1940#ifdef PRINTPIPE
1925 int nrows, row_start; 1941 int nrows, row_start;
1926 FILE *fd; 1942 FILE *fd = popen_printer ();
1927 1943
1928 if ((fd = popen_printer ()) == NULL) 1944 if (!fd)
1929 return; 1945 return;
1930 1946
1931 if (fullhist) 1947 if (fullhist)
1932 { 1948 {
1933 nrows = nrow - top_row; 1949 nrows = nrow - top_row;
2203 continue; 2219 continue;
2204 2220
2205 // redraw one or more characters 2221 // redraw one or more characters
2206 2222
2207 // seek to the beginning of wide characters 2223 // seek to the beginning of wide characters
2208 while (stp[col] == NOCHAR && col > 0) 2224 while (expect_false (stp[col] == NOCHAR && col > 0))
2209 --col; 2225 --col;
2210 2226
2211 rend_t rend = srp[col]; /* screen rendition (target rendtion) */ 2227 rend_t rend = srp[col]; /* screen rendition (target rendtion) */
2212 text_t *text = stp + col; 2228 text_t *text = stp + col;
2213 int count = 1; 2229 int count = 1;
2250 2266
2251 col--; /* went one too far. move back */ 2267 col--; /* went one too far. move back */
2252 count -= i; /* dump any matching trailing chars */ 2268 count -= i; /* dump any matching trailing chars */
2253 2269
2254 // sometimes we optimize away the trailing NOCHAR's, add them back 2270 // sometimes we optimize away the trailing NOCHAR's, add them back
2255 while (i && text[count] == NOCHAR) 2271 while (expect_false (i && text[count] == NOCHAR))
2256 count++, i--; 2272 count++, i--;
2257 2273
2258 /* 2274 /*
2259 * Determine the attributes for the string 2275 * Determine the attributes for the string
2260 */ 2276 */
2261 int fore = fgcolor_of (rend); // desired foreground 2277 int fore = fgcolor_of (rend); // desired foreground
2262 int back = bgcolor_of (rend); // desired background 2278 int back = bgcolor_of (rend); // desired background
2263 2279
2264 // only do special processing if any attributes are set, which is unlikely 2280 // only do special processing if any attributes are set, which is unlikely
2265 if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) 2281 if (expect_false (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)))
2266 { 2282 {
2267 bool invert = rend & RS_RVid; 2283 bool invert = rend & RS_RVid;
2268 2284
2269#ifndef NO_BOLD_UNDERLINE_REVERSE 2285#ifndef NO_BOLD_UNDERLINE_REVERSE
2270 if (rend & RS_Bold && fore == Color_fg) 2286 if (rend & RS_Bold && fore == Color_fg)
2353 /* 2369 /*
2354 * Actually do the drawing of the string here 2370 * Actually do the drawing of the string here
2355 */ 2371 */
2356 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)]; 2372 rxvt_font *font = (*fontset[GET_STYLE (rend)])[GET_FONT (rend)];
2357 2373
2358 if (have_bg && back == Color_bg) 2374 if (expect_true (have_bg && back == Color_bg))
2359 { 2375 {
2360 // this is very ugly, maybe push it into ->draw? 2376 // this is very ugly, maybe push it into ->draw?
2361 2377
2362 for (i = 0; i < count; i++) /* don't draw empty strings */ 2378 for (i = 0; i < count; i++) /* don't draw empty strings */
2363 if (text[i] != ' ') 2379 if (text[i] != ' ')
2370 did_clear: ; 2386 did_clear: ;
2371 } 2387 }
2372 else 2388 else
2373 font->draw (*drawable, xpixel, ypixel, text, count, fore, back); 2389 font->draw (*drawable, xpixel, ypixel, text, count, fore, back);
2374 2390
2375 if (rend & RS_Uline && font->descent > 1 && fore != back) 2391 if (expect_false (rend & RS_Uline && font->descent > 1 && fore != back))
2376 { 2392 {
2377#if ENABLE_FRILLS 2393#if ENABLE_FRILLS
2378 if (ISSET_PIXCOLOR (Color_underline)) 2394 if (ISSET_PIXCOLOR (Color_underline))
2379 XSetForeground (dpy, gc, pix_colors[Color_underline]); 2395 XSetForeground (dpy, gc, pix_colors[Color_underline]);
2380 else 2396 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines