aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Lohmann <20h@r-36.net>2012-08-30 21:17:54 +0200
committerChristoph Lohmann <20h@r-36.net>2012-08-30 21:17:54 +0200
commitc58950f2efd8f203e72add7b22e7f5b973c09a7d (patch)
tree5524eb86864c0e30823bf07d999293a12e182557
parent91fa81dbac4f09de234921cdf5afacb8c8295919 (diff)
downloadst-c58950f2efd8f203e72add7b22e7f5b973c09a7d.tar.gz
st-c58950f2efd8f203e72add7b22e7f5b973c09a7d.zip
Applying the CBT patch of Roberto Vargas. Thanks.
-rw-r--r--st.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/st.c b/st.c
index 5b98c6f..8cc0e1d 100644
--- a/st.c
+++ b/st.c
@@ -97,11 +97,11 @@ enum glyph_state {
97}; 97};
98 98
99enum term_mode { 99enum term_mode {
100 MODE_WRAP = 1, 100 MODE_WRAP = 1,
101 MODE_INSERT = 2, 101 MODE_INSERT = 2,
102 MODE_APPKEYPAD = 4, 102 MODE_APPKEYPAD = 4,
103 MODE_ALTSCREEN = 8, 103 MODE_ALTSCREEN = 8,
104 MODE_CRLF = 16, 104 MODE_CRLF = 16,
105 MODE_MOUSEBTN = 32, 105 MODE_MOUSEBTN = 32,
106 MODE_MOUSEMOTION = 64, 106 MODE_MOUSEMOTION = 64,
107 MODE_MOUSE = 32|64, 107 MODE_MOUSE = 32|64,
@@ -110,8 +110,8 @@ enum term_mode {
110 110
111enum escape_state { 111enum escape_state {
112 ESC_START = 1, 112 ESC_START = 1,
113 ESC_CSI = 2, 113 ESC_CSI = 2,
114 ESC_STR = 4, /* DSC, OSC, PM, APC */ 114 ESC_STR = 4, /* DSC, OSC, PM, APC */
115 ESC_ALTCHARSET = 8, 115 ESC_ALTCHARSET = 8,
116 ESC_STR_END = 16, /* a final string was encountered */ 116 ESC_STR_END = 16, /* a final string was encountered */
117}; 117};
@@ -152,21 +152,21 @@ typedef struct {
152/* ESC '[' [[ [<priv>] <arg> [;]] <mode>] */ 152/* ESC '[' [[ [<priv>] <arg> [;]] <mode>] */
153typedef struct { 153typedef struct {
154 char buf[ESC_BUF_SIZ]; /* raw string */ 154 char buf[ESC_BUF_SIZ]; /* raw string */
155 int len; /* raw string length */ 155 int len; /* raw string length */
156 char priv; 156 char priv;
157 int arg[ESC_ARG_SIZ]; 157 int arg[ESC_ARG_SIZ];
158 int narg; /* nb of args */ 158 int narg; /* nb of args */
159 char mode; 159 char mode;
160} CSIEscape; 160} CSIEscape;
161 161
162/* STR Escape sequence structs */ 162/* STR Escape sequence structs */
163/* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */ 163/* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */
164typedef struct { 164typedef struct {
165 char type; /* ESC type ... */ 165 char type; /* ESC type ... */
166 char buf[STR_BUF_SIZ]; /* raw string */ 166 char buf[STR_BUF_SIZ]; /* raw string */
167 int len; /* raw string length */ 167 int len; /* raw string length */
168 char *args[STR_ARG_SIZ]; 168 char *args[STR_ARG_SIZ];
169 int narg; /* nb of args */ 169 int narg; /* nb of args */
170} STREscape; 170} STREscape;
171 171
172/* Internal representation of the screen */ 172/* Internal representation of the screen */
@@ -262,7 +262,7 @@ static void tinsertblankline(int);
262static void tmoveto(int, int); 262static void tmoveto(int, int);
263static void tnew(int, int); 263static void tnew(int, int);
264static void tnewline(int); 264static void tnewline(int);
265static void tputtab(void); 265static void tputtab(bool);
266static void tputc(char*); 266static void tputc(char*);
267static void treset(void); 267static void treset(void);
268static int tresize(int, int); 268static int tresize(int, int);
@@ -1243,7 +1243,7 @@ csihandle(void) {
1243 case 'I': /* CHT -- Cursor Forward Tabulation <n> tab stops */ 1243 case 'I': /* CHT -- Cursor Forward Tabulation <n> tab stops */
1244 DEFAULT(csiescseq.arg[0], 1); 1244 DEFAULT(csiescseq.arg[0], 1);
1245 while (csiescseq.arg[0]--) 1245 while (csiescseq.arg[0]--)
1246 tputtab(); 1246 tputtab(1);
1247 break; 1247 break;
1248 case 'J': /* ED -- Clear screen */ 1248 case 'J': /* ED -- Clear screen */
1249 sel.bx = -1; 1249 sel.bx = -1;
@@ -1356,7 +1356,11 @@ csihandle(void) {
1356 DEFAULT(csiescseq.arg[0], 1); 1356 DEFAULT(csiescseq.arg[0], 1);
1357 tdeletechar(csiescseq.arg[0]); 1357 tdeletechar(csiescseq.arg[0]);
1358 break; 1358 break;
1359 /* XXX: (CSI n Z) CBT -- Cursor Backward Tabulation <n> tab stops */ 1359 case 'Z': /* CBT -- Cursor Backward Tabulation <n> tab stops */
1360 DEFAULT(csiescseq.arg[0], 1);
1361 while (csiescseq.arg[0]--)
1362 tputtab(0);
1363 break;
1360 case 'd': /* VPA -- Move to <row> */ 1364 case 'd': /* VPA -- Move to <row> */
1361 DEFAULT(csiescseq.arg[0], 1); 1365 DEFAULT(csiescseq.arg[0], 1);
1362 tmoveto(term.c.x, csiescseq.arg[0]-1); 1366 tmoveto(term.c.x, csiescseq.arg[0]-1);
@@ -1528,11 +1532,20 @@ strreset(void) {
1528} 1532}
1529 1533
1530void 1534void
1531tputtab(void) { 1535tputtab(bool forward) {
1532 unsigned x; 1536 unsigned x = term.c.x;
1533 1537
1534 for (x = term.c.x + 1; x < term.col && !term.tabs[x]; ++x) 1538 if (forward) {
1535 /* nothing */ ; 1539 if (x == term.col)
1540 return;
1541 for (++x; x < term.col && !term.tabs[x]; ++x)
1542 /* nothing */ ;
1543 } else {
1544 if (x == 0)
1545 return;
1546 for (--x; x > 0 && !term.tabs[x]; --x)
1547 /* nothing */ ;
1548 }
1536 tmoveto(x, term.c.y); 1549 tmoveto(x, term.c.y);
1537} 1550}
1538 1551
@@ -1650,7 +1663,7 @@ tputc(char *c) {
1650 sel.bx = -1; 1663 sel.bx = -1;
1651 switch(ascii) { 1664 switch(ascii) {
1652 case '\t': 1665 case '\t':
1653 tputtab(); 1666 tputtab(1);
1654 break; 1667 break;
1655 case '\b': 1668 case '\b':
1656 tmoveto(term.c.x-1, term.c.y); 1669 tmoveto(term.c.x-1, term.c.y);
@@ -1806,8 +1819,8 @@ void
1806xclear(int x1, int y1, int x2, int y2) { 1819xclear(int x1, int y1, int x2, int y2) {
1807 XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? DefaultFG : DefaultBG]); 1820 XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? DefaultFG : DefaultBG]);
1808 XFillRectangle(xw.dpy, xw.buf, dc.gc, 1821 XFillRectangle(xw.dpy, xw.buf, dc.gc,
1809 BORDER + x1 * xw.cw, BORDER + y1 * xw.ch, 1822 BORDER + x1 * xw.cw, BORDER + y1 * xw.ch,
1810 (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch); 1823 (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch);
1811} 1824}
1812 1825
1813void 1826void
@@ -1982,8 +1995,8 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
1982/* copy buffer pixmap to screen pixmap */ 1995/* copy buffer pixmap to screen pixmap */
1983void 1996void
1984xcopy() { 1997xcopy() {
1985 XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}}; 1998 XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}};
1986 XdbeSwapBuffers(xw.dpy, swpinfo, 1); 1999 XdbeSwapBuffers(xw.dpy, swpinfo, 1);
1987 2000
1988} 2001}
1989 2002
@@ -2080,8 +2093,8 @@ expose(XEvent *ev) {
2080 if(xw.state & WIN_REDRAW) { 2093 if(xw.state & WIN_REDRAW) {
2081 if(!e->count) 2094 if(!e->count)
2082 xw.state &= ~WIN_REDRAW; 2095 xw.state &= ~WIN_REDRAW;
2083 } 2096 }
2084 xcopy(); 2097 xcopy();
2085} 2098}
2086 2099
2087void 2100void