aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto E. Vargas Caballero <k0ga@shike2.com>2012-08-29 19:59:37 +0200
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2012-08-29 19:59:37 +0200
commitee7fd748ac7bfabda2ac37251d230b45adb3e138 (patch)
treeb350439ebeb67f710486ce3d881b6a86ed973cb3
parentc6853fe18564437fe0a4cb06565a0a7d63d40b5a (diff)
downloadst-ee7fd748ac7bfabda2ac37251d230b45adb3e138.tar.gz
st-ee7fd748ac7bfabda2ac37251d230b45adb3e138.zip
Add tabs field into Term struct
Tabs stop are simulated in st using a fixed size of 8, always, without be worried about sequences changing the tab stops. A user can put a tab stop in each horizontal position of the screen, so we need at least one flag for each column of the screen. In the same way as dirty flags is used for the rows, it is used a bool dinamic array. Signed-off-by: Roberto E. Vargas Caballero <k0ga@shike2.com> --- st.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
-rw-r--r--st.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/st.c b/st.c
index 4fc4d3d..d169ddf 100644
--- a/st.c
+++ b/st.c
@@ -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
848void 849void
849treset(void) { 850treset(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 */