diff options
| author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2011-10-20 23:20:59 +0200 |
|---|---|---|
| committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2011-10-20 23:20:59 +0200 |
| commit | 0dbf9c8c12a5de35d1cef22349ab80e8f0a8f10e (patch) | |
| tree | cc38fb000fc9c5b3fcbb3f74d8a11eaf98fbe91e | |
| parent | 907cb8bfa69926616639f9a19127117b37326029 (diff) | |
| download | st-0dbf9c8c12a5de35d1cef22349ab80e8f0a8f10e.tar.gz st-0dbf9c8c12a5de35d1cef22349ab80e8f0a8f10e.zip | |
add dirty flag for lines
| -rw-r--r-- | st.c | 43 |
1 files changed, 39 insertions, 4 deletions
| @@ -111,6 +111,7 @@ typedef struct { | |||
| 111 | int col; /* nb col */ | 111 | int col; /* nb col */ |
| 112 | Line* line; /* screen */ | 112 | Line* line; /* screen */ |
| 113 | Line* alt; /* alternate screen */ | 113 | Line* alt; /* alternate screen */ |
| 114 | char* dirty; /* dirtyness of lines */ | ||
| 114 | TCursor c; /* cursor */ | 115 | TCursor c; /* cursor */ |
| 115 | int top; /* top scroll limit */ | 116 | int top; /* top scroll limit */ |
| 116 | int bot; /* bottom scroll limit */ | 117 | int bot; /* bottom scroll limit */ |
| @@ -203,6 +204,7 @@ static void tsetattr(int*, int); | |||
| 203 | static void tsetchar(char*); | 204 | static void tsetchar(char*); |
| 204 | static void tsetscroll(int, int); | 205 | static void tsetscroll(int, int); |
| 205 | static void tswapscreen(void); | 206 | static void tswapscreen(void); |
| 207 | static void tfulldirt(void); | ||
| 206 | 208 | ||
| 207 | static void ttynew(void); | 209 | static void ttynew(void); |
| 208 | static void ttyread(void); | 210 | static void ttyread(void); |
| @@ -749,6 +751,14 @@ ttyresize(int x, int y) { | |||
| 749 | } | 751 | } |
| 750 | 752 | ||
| 751 | void | 753 | void |
| 754 | tfulldirt(void) | ||
| 755 | { | ||
| 756 | int i; | ||
| 757 | for(i = 0; i < term.row; i++) | ||
| 758 | term.dirty[i] = 1; | ||
| 759 | } | ||
| 760 | |||
| 761 | void | ||
| 752 | tcursor(int mode) { | 762 | tcursor(int mode) { |
| 753 | static TCursor c; | 763 | static TCursor c; |
| 754 | 764 | ||
| @@ -777,9 +787,12 @@ tnew(int col, int row) { | |||
| 777 | term.row = row, term.col = col; | 787 | term.row = row, term.col = col; |
| 778 | term.line = malloc(term.row * sizeof(Line)); | 788 | term.line = malloc(term.row * sizeof(Line)); |
| 779 | term.alt = malloc(term.row * sizeof(Line)); | 789 | term.alt = malloc(term.row * sizeof(Line)); |
| 790 | term.dirty = malloc(term.row * sizeof(*term.dirty)); | ||
| 791 | |||
| 780 | for(row = 0; row < term.row; row++) { | 792 | for(row = 0; row < term.row; row++) { |
| 781 | term.line[row] = malloc(term.col * sizeof(Glyph)); | 793 | term.line[row] = malloc(term.col * sizeof(Glyph)); |
| 782 | term.alt [row] = malloc(term.col * sizeof(Glyph)); | 794 | term.alt [row] = malloc(term.col * sizeof(Glyph)); |
| 795 | term.dirty[row] = 0; | ||
| 783 | } | 796 | } |
| 784 | /* setup screen */ | 797 | /* setup screen */ |
| 785 | treset(); | 798 | treset(); |
| @@ -791,6 +804,7 @@ tswapscreen(void) { | |||
| 791 | term.line = term.alt; | 804 | term.line = term.alt; |
| 792 | term.alt = tmp; | 805 | term.alt = tmp; |
| 793 | term.mode ^= MODE_ALTSCREEN; | 806 | term.mode ^= MODE_ALTSCREEN; |
| 807 | tfulldirt(); | ||
| 794 | } | 808 | } |
| 795 | 809 | ||
| 796 | void | 810 | void |
| @@ -806,6 +820,9 @@ tscrolldown(int orig, int n) { | |||
| 806 | temp = term.line[i]; | 820 | temp = term.line[i]; |
| 807 | term.line[i] = term.line[i-n]; | 821 | term.line[i] = term.line[i-n]; |
| 808 | term.line[i-n] = temp; | 822 | term.line[i-n] = temp; |
| 823 | |||
| 824 | term.dirty[i] = 1; | ||
| 825 | term.dirty[i-n] = 1; | ||
| 809 | } | 826 | } |
| 810 | 827 | ||
| 811 | selscroll(orig, n); | 828 | selscroll(orig, n); |
| @@ -823,6 +840,9 @@ tscrollup(int orig, int n) { | |||
| 823 | temp = term.line[i]; | 840 | temp = term.line[i]; |
| 824 | term.line[i] = term.line[i+n]; | 841 | term.line[i] = term.line[i+n]; |
| 825 | term.line[i+n] = temp; | 842 | term.line[i+n] = temp; |
| 843 | |||
| 844 | term.dirty[i] = 1; | ||
| 845 | term.dirty[i+n] = 1; | ||
| 826 | } | 846 | } |
| 827 | 847 | ||
| 828 | selscroll(orig, -n); | 848 | selscroll(orig, -n); |
| @@ -896,6 +916,7 @@ tmoveto(int x, int y) { | |||
| 896 | 916 | ||
| 897 | void | 917 | void |
| 898 | tsetchar(char *c) { | 918 | tsetchar(char *c) { |
| 919 | term.dirty[term.c.y] = 1; | ||
| 899 | term.line[term.c.y][term.c.x] = term.c.attr; | 920 | term.line[term.c.y][term.c.x] = term.c.attr; |
| 900 | memcpy(term.line[term.c.y][term.c.x].c, c, UTF_SIZ); | 921 | memcpy(term.line[term.c.y][term.c.x].c, c, UTF_SIZ); |
| 901 | term.line[term.c.y][term.c.x].state |= GLYPH_SET; | 922 | term.line[term.c.y][term.c.x].state |= GLYPH_SET; |
| @@ -915,9 +936,11 @@ tclearregion(int x1, int y1, int x2, int y2) { | |||
| 915 | LIMIT(y1, 0, term.row-1); | 936 | LIMIT(y1, 0, term.row-1); |
| 916 | LIMIT(y2, 0, term.row-1); | 937 | LIMIT(y2, 0, term.row-1); |
| 917 | 938 | ||
| 918 | for(y = y1; y <= y2; y++) | 939 | for(y = y1; y <= y2; y++) { |
| 940 | term.dirty[y] = 1; | ||
| 919 | for(x = x1; x <= x2; x++) | 941 | for(x = x1; x <= x2; x++) |
| 920 | term.line[y][x].state = 0; | 942 | term.line[y][x].state = 0; |
| 943 | } | ||
| 921 | } | 944 | } |
| 922 | 945 | ||
| 923 | void | 946 | void |
| @@ -925,6 +948,8 @@ tdeletechar(int n) { | |||
| 925 | int src = term.c.x + n; | 948 | int src = term.c.x + n; |
| 926 | int dst = term.c.x; | 949 | int dst = term.c.x; |
| 927 | int size = term.col - src; | 950 | int size = term.col - src; |
| 951 | |||
| 952 | term.dirty[term.c.y] = 1; | ||
| 928 | 953 | ||
| 929 | if(src >= term.col) { | 954 | if(src >= term.col) { |
| 930 | tclearregion(term.c.x, term.c.y, term.col-1, term.c.y); | 955 | tclearregion(term.c.x, term.c.y, term.col-1, term.c.y); |
| @@ -940,6 +965,8 @@ tinsertblank(int n) { | |||
| 940 | int dst = src + n; | 965 | int dst = src + n; |
| 941 | int size = term.col - dst; | 966 | int size = term.col - dst; |
| 942 | 967 | ||
| 968 | term.dirty[term.c.y] = 1; | ||
| 969 | |||
| 943 | if(dst >= term.col) { | 970 | if(dst >= term.col) { |
| 944 | tclearregion(term.c.x, term.c.y, term.col-1, term.c.y); | 971 | tclearregion(term.c.x, term.c.y, term.col-1, term.c.y); |
| 945 | return; | 972 | return; |
| @@ -1411,7 +1438,8 @@ tputc(char *c) { | |||
| 1411 | } | 1438 | } |
| 1412 | } | 1439 | } |
| 1413 | } else { | 1440 | } else { |
| 1414 | if(sel.bx != -1 && BETWEEN(term.c.y, sel.by, sel.ey)) sel.bx = -1; | 1441 | if(sel.bx != -1 && BETWEEN(term.c.y, sel.by, sel.ey)) |
| 1442 | sel.bx = -1; | ||
| 1415 | switch(ascii) { | 1443 | switch(ascii) { |
| 1416 | case '\t': | 1444 | case '\t': |
| 1417 | tputtab(); | 1445 | tputtab(); |
| @@ -1479,9 +1507,11 @@ tresize(int col, int row) { | |||
| 1479 | /* resize to new height */ | 1507 | /* resize to new height */ |
| 1480 | term.line = realloc(term.line, row * sizeof(Line)); | 1508 | term.line = realloc(term.line, row * sizeof(Line)); |
| 1481 | term.alt = realloc(term.alt, row * sizeof(Line)); | 1509 | term.alt = realloc(term.alt, row * sizeof(Line)); |
| 1510 | term.dirty = realloc(term.dirty, row * sizeof(*term.dirty)); | ||
| 1482 | 1511 | ||
| 1483 | /* resize each row to new width, zero-pad if needed */ | 1512 | /* resize each row to new width, zero-pad if needed */ |
| 1484 | for(i = 0; i < minrow; i++) { | 1513 | for(i = 0; i < minrow; i++) { |
| 1514 | term.dirty[i] = 1; | ||
| 1485 | term.line[i] = realloc(term.line[i], col * sizeof(Glyph)); | 1515 | term.line[i] = realloc(term.line[i], col * sizeof(Glyph)); |
| 1486 | term.alt[i] = realloc(term.alt[i], col * sizeof(Glyph)); | 1516 | term.alt[i] = realloc(term.alt[i], col * sizeof(Glyph)); |
| 1487 | for(x = mincol; x < col; x++) { | 1517 | for(x = mincol; x < col; x++) { |
| @@ -1492,6 +1522,7 @@ tresize(int col, int row) { | |||
| 1492 | 1522 | ||
| 1493 | /* allocate any new rows */ | 1523 | /* allocate any new rows */ |
| 1494 | for(/* i == minrow */; i < row; i++) { | 1524 | for(/* i == minrow */; i < row; i++) { |
| 1525 | term.dirty[i] = 1; | ||
| 1495 | term.line[i] = calloc(col, sizeof(Glyph)); | 1526 | term.line[i] = calloc(col, sizeof(Glyph)); |
| 1496 | term.alt [i] = calloc(col, sizeof(Glyph)); | 1527 | term.alt [i] = calloc(col, sizeof(Glyph)); |
| 1497 | } | 1528 | } |
| @@ -1502,6 +1533,7 @@ tresize(int col, int row) { | |||
| 1502 | tmoveto(term.c.x, term.c.y); | 1533 | tmoveto(term.c.x, term.c.y); |
| 1503 | /* reset scrolling region */ | 1534 | /* reset scrolling region */ |
| 1504 | tsetscroll(0, row-1); | 1535 | tsetscroll(0, row-1); |
| 1536 | |||
| 1505 | return (slide > 0); | 1537 | return (slide > 0); |
| 1506 | } | 1538 | } |
| 1507 | 1539 | ||
| @@ -1792,8 +1824,11 @@ drawregion(int x1, int y1, int x2, int y2) { | |||
| 1792 | if(!(xw.state & WIN_VISIBLE)) | 1824 | if(!(xw.state & WIN_VISIBLE)) |
| 1793 | return; | 1825 | return; |
| 1794 | 1826 | ||
| 1795 | xclear(x1, y1, x2-1, y2-1); | ||
| 1796 | for(y = y1; y < y2; y++) { | 1827 | for(y = y1; y < y2; y++) { |
| 1828 | if(!term.dirty[y]) | ||
| 1829 | continue; | ||
| 1830 | xclear(0, y, term.col, y); | ||
| 1831 | term.dirty[y] = 0; | ||
| 1797 | base = term.line[y][0]; | 1832 | base = term.line[y][0]; |
| 1798 | ic = ib = ox = 0; | 1833 | ic = ib = ox = 0; |
| 1799 | for(x = x1; x < x2; x++) { | 1834 | for(x = x1; x < x2; x++) { |
| @@ -1801,7 +1836,7 @@ drawregion(int x1, int y1, int x2, int y2) { | |||
| 1801 | if(sel.bx != -1 && *(new.c) && selected(x, y)) | 1836 | if(sel.bx != -1 && *(new.c) && selected(x, y)) |
| 1802 | new.mode ^= ATTR_REVERSE; | 1837 | new.mode ^= ATTR_REVERSE; |
| 1803 | if(ib > 0 && (!(new.state & GLYPH_SET) || ATTRCMP(base, new) || | 1838 | if(ib > 0 && (!(new.state & GLYPH_SET) || ATTRCMP(base, new) || |
| 1804 | ib >= DRAW_BUF_SIZ-UTF_SIZ)) { | 1839 | ib >= DRAW_BUF_SIZ-UTF_SIZ)) { |
| 1805 | xdraws(buf, base, ox, y, ic, ib); | 1840 | xdraws(buf, base, ox, y, ic, ib); |
| 1806 | ic = ib = 0; | 1841 | ic = ib = 0; |
| 1807 | } | 1842 | } |
