diff options
| -rw-r--r-- | st.c | 22 |
1 files changed, 19 insertions, 3 deletions
| @@ -164,7 +164,7 @@ typedef struct { | |||
| 164 | int col; /* nb col */ | 164 | int col; /* nb col */ |
| 165 | Line* line; /* screen */ | 165 | Line* line; /* screen */ |
| 166 | Line* alt; /* alternate screen */ | 166 | Line* alt; /* alternate screen */ |
| 167 | bool* dirty; /* dirtyness of lines */ | 167 | bool* dirty; /* dirtyness of lines */ |
| 168 | TCursor c; /* cursor */ | 168 | TCursor c; /* cursor */ |
| 169 | int top; /* top scroll limit */ | 169 | int top; /* top scroll limit */ |
| 170 | int bot; /* bottom scroll limit */ | 170 | int bot; /* bottom scroll limit */ |
| @@ -172,6 +172,7 @@ typedef struct { | |||
| 172 | int esc; /* escape state flags */ | 172 | int esc; /* escape state flags */ |
| 173 | char title[ESC_TITLE_SIZ]; | 173 | char title[ESC_TITLE_SIZ]; |
| 174 | int titlelen; | 174 | int titlelen; |
| 175 | bool *tabs; | ||
| 175 | } Term; | 176 | } Term; |
| 176 | 177 | ||
| 177 | /* Purely graphic info */ | 178 | /* Purely graphic info */ |
| @@ -847,12 +848,16 @@ tcursor(int mode) { | |||
| 847 | 848 | ||
| 848 | void | 849 | void |
| 849 | treset(void) { | 850 | treset(void) { |
| 851 | unsigned i; | ||
| 850 | term.c = (TCursor){{ | 852 | term.c = (TCursor){{ |
| 851 | .mode = ATTR_NULL, | 853 | .mode = ATTR_NULL, |
| 852 | .fg = DefaultFG, | 854 | .fg = DefaultFG, |
| 853 | .bg = DefaultBG | 855 | .bg = DefaultBG |
| 854 | }, .x = 0, .y = 0, .state = CURSOR_DEFAULT}; | 856 | }, .x = 0, .y = 0, .state = CURSOR_DEFAULT}; |
| 855 | 857 | ||
| 858 | memset(term.tabs, 0, term.col * sizeof(*term.tabs)); | ||
| 859 | for (i = TAB; i < term.col; i += TAB) | ||
| 860 | term.tabs[i] = 1; | ||
| 856 | term.top = 0, term.bot = term.row - 1; | 861 | term.top = 0, term.bot = term.row - 1; |
| 857 | term.mode = MODE_WRAP; | 862 | term.mode = MODE_WRAP; |
| 858 | tclearregion(0, 0, term.col-1, term.row-1); | 863 | tclearregion(0, 0, term.col-1, term.row-1); |
| @@ -865,12 +870,14 @@ tnew(int col, int row) { | |||
| 865 | term.line = malloc(term.row * sizeof(Line)); | 870 | term.line = malloc(term.row * sizeof(Line)); |
| 866 | term.alt = malloc(term.row * sizeof(Line)); | 871 | term.alt = malloc(term.row * sizeof(Line)); |
| 867 | term.dirty = malloc(term.row * sizeof(*term.dirty)); | 872 | term.dirty = malloc(term.row * sizeof(*term.dirty)); |
| 873 | term.tabs = malloc(term.col * sizeof(*term.tabs)); | ||
| 868 | 874 | ||
| 869 | for(row = 0; row < term.row; row++) { | 875 | for(row = 0; row < term.row; row++) { |
| 870 | term.line[row] = malloc(term.col * sizeof(Glyph)); | 876 | term.line[row] = malloc(term.col * sizeof(Glyph)); |
| 871 | term.alt [row] = malloc(term.col * sizeof(Glyph)); | 877 | term.alt [row] = malloc(term.col * sizeof(Glyph)); |
| 872 | term.dirty[row] = 0; | 878 | term.dirty[row] = 0; |
| 873 | } | 879 | } |
| 880 | memset(term.tabs, 0, term.col * sizeof(*term.tabs)); | ||
| 874 | /* setup screen */ | 881 | /* setup screen */ |
| 875 | treset(); | 882 | treset(); |
| 876 | } | 883 | } |
| @@ -1588,6 +1595,7 @@ tresize(int col, int row) { | |||
| 1588 | term.line = realloc(term.line, row * sizeof(Line)); | 1595 | term.line = realloc(term.line, row * sizeof(Line)); |
| 1589 | term.alt = realloc(term.alt, row * sizeof(Line)); | 1596 | term.alt = realloc(term.alt, row * sizeof(Line)); |
| 1590 | term.dirty = realloc(term.dirty, row * sizeof(*term.dirty)); | 1597 | term.dirty = realloc(term.dirty, row * sizeof(*term.dirty)); |
| 1598 | term.tabs = realloc(term.tabs, col * sizeof(*term.tabs)); | ||
| 1591 | 1599 | ||
| 1592 | /* resize each row to new width, zero-pad if needed */ | 1600 | /* resize each row to new width, zero-pad if needed */ |
| 1593 | for(i = 0; i < minrow; i++) { | 1601 | for(i = 0; i < minrow; i++) { |
| @@ -1606,7 +1614,15 @@ tresize(int col, int row) { | |||
| 1606 | term.line[i] = calloc(col, sizeof(Glyph)); | 1614 | term.line[i] = calloc(col, sizeof(Glyph)); |
| 1607 | term.alt [i] = calloc(col, sizeof(Glyph)); | 1615 | term.alt [i] = calloc(col, sizeof(Glyph)); |
| 1608 | } | 1616 | } |
| 1609 | 1617 | if (col > term.col) { | |
| 1618 | bool *bp = term.tabs + term.col; | ||
| 1619 | |||
| 1620 | memset(bp, 0, sizeof(*term.tabs) * (col - term.col)); | ||
| 1621 | while (--bp > term.tabs && !*bp) | ||
| 1622 | /* nothing */ ; | ||
| 1623 | for (bp += TAB; bp < term.tabs + col; bp += TAB) | ||
| 1624 | *bp = 1; | ||
| 1625 | } | ||
| 1610 | /* update terminal size */ | 1626 | /* update terminal size */ |
| 1611 | term.col = col, term.row = row; | 1627 | term.col = col, term.row = row; |
| 1612 | /* make use of the LIMIT in tmoveto */ | 1628 | /* make use of the LIMIT in tmoveto */ |
