aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h1
-rw-r--r--st.c48
2 files changed, 21 insertions, 28 deletions
diff --git a/config.h b/config.h
index bb490ab..53795c6 100644
--- a/config.h
+++ b/config.h
@@ -30,6 +30,7 @@ static const char *colorname[] = {
30#define DefaultBG 0 30#define DefaultBG 0
31#define DefaultCS 1 31#define DefaultCS 1
32#define BellCol DefaultFG 32#define BellCol DefaultFG
33#define BellTime 30000 /* microseconds */
33 34
34/* special keys */ 35/* special keys */
35static Key key[] = { 36static Key key[] = {
diff --git a/st.c b/st.c
index eabc0c5..9b77a0b 100644
--- a/st.c
+++ b/st.c
@@ -67,6 +67,7 @@ typedef struct {
67 Glyph attr; /* current char attributes */ 67 Glyph attr; /* current char attributes */
68 int x; 68 int x;
69 int y; 69 int y;
70 char hide;
70} TCursor; 71} TCursor;
71 72
72/* CSI Escape sequence structs */ 73/* CSI Escape sequence structs */
@@ -86,7 +87,6 @@ typedef struct {
86 int col; /* nb col */ 87 int col; /* nb col */
87 Line* line; /* screen */ 88 Line* line; /* screen */
88 TCursor c; /* cursor */ 89 TCursor c; /* cursor */
89 char hidec;
90 int top; /* top scroll limit */ 90 int top; /* top scroll limit */
91 int bot; /* bottom scroll limit */ 91 int bot; /* bottom scroll limit */
92 int mode; /* terminal mode flags */ 92 int mode; /* terminal mode flags */
@@ -221,17 +221,16 @@ die(const char *errstr, ...) {
221void 221void
222execsh(void) { 222execsh(void) {
223 char *args[3] = {getenv("SHELL"), "-i", NULL}; 223 char *args[3] = {getenv("SHELL"), "-i", NULL};
224 DEFAULT(args[0], "/bin/sh"); /* default shell if getenv() failed */ 224 DEFAULT(args[0], "/bin/sh"); /* if getenv() failed */
225 putenv("TERM=" TNAME); 225 putenv("TERM=" TNAME);
226 execvp(args[0], args); 226 execvp(args[0], args);
227} 227}
228 228
229void 229void
230xbell(void) { /* visual bell */ 230xbell(void) {
231 XRectangle r = { BORDER, BORDER, xw.bufw, xw.bufh };
232 XSetForeground(xw.dis, dc.gc, dc.col[BellCol]); 231 XSetForeground(xw.dis, dc.gc, dc.col[BellCol]);
233 XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1); 232 XFillRectangle(xw.dis, xw.win, dc.gc, BORDER, BORDER, xw.bufw, xw.bufh);
234 /* usleep(30000); */ 233 usleep(BellTime);
235 draw(SCREEN_REDRAW); 234 draw(SCREEN_REDRAW);
236} 235}
237 236
@@ -325,11 +324,12 @@ tcursor(int mode) {
325 324
326void 325void
327treset(void) { 326treset(void) {
328 term.c.attr.mode = ATTR_NULL; 327 term.c = (TCursor){{
329 term.c.attr.fg = DefaultFG; 328 .mode = ATTR_NULL,
330 term.c.attr.bg = DefaultBG; 329 .fg = DefaultFG,
331 term.c.x = term.c.y = 0; 330 .bg = DefaultBG
332 term.hidec = 0; 331 }, .x = 0, .y = 0, .hide = 0};
332
333 term.top = 0, term.bot = term.row - 1; 333 term.top = 0, term.bot = term.row - 1;
334 term.mode = MODE_WRAP; 334 term.mode = MODE_WRAP;
335 tclearregion(0, 0, term.col-1, term.row-1); 335 tclearregion(0, 0, term.col-1, term.row-1);
@@ -337,21 +337,13 @@ treset(void) {
337 337
338void 338void
339tnew(int col, int row) { 339tnew(int col, int row) {
340 /* screen size */ 340 /* set screen size */
341 term.row = row, term.col = col; 341 term.row = row, term.col = col;
342 term.top = 0, term.bot = term.row - 1; 342 term.line = malloc(term.row * sizeof(Line));
343 /* mode */
344 term.mode = MODE_WRAP;
345 /* cursor */
346 term.c.attr.mode = ATTR_NULL;
347 term.c.attr.fg = DefaultFG;
348 term.c.attr.bg = DefaultBG;
349 term.c.x = term.c.y = 0;
350 term.hidec = 0;
351 /* allocate screen */
352 term.line = calloc(term.row, sizeof(Line));
353 for(row = 0 ; row < term.row; row++) 343 for(row = 0 ; row < term.row; row++)
354 term.line[row] = calloc(term.col, sizeof(Glyph)); 344 term.line[row] = malloc(term.col * sizeof(Glyph));
345 /* setup screen */
346 treset();
355} 347}
356 348
357void 349void
@@ -718,7 +710,7 @@ csihandle(void) {
718 case 12: /* att610 -- Stop blinking cursor (IGNORED) */ 710 case 12: /* att610 -- Stop blinking cursor (IGNORED) */
719 break; 711 break;
720 case 25: 712 case 25:
721 term.hidec = 1; 713 term.c.hide = 1;
722 break; 714 break;
723 case 1048: /* XXX: no alt. screen to erase/save */ 715 case 1048: /* XXX: no alt. screen to erase/save */
724 case 1049: 716 case 1049:
@@ -767,7 +759,7 @@ csihandle(void) {
767 case 12: /* att610 -- Start blinking cursor (IGNORED) */ 759 case 12: /* att610 -- Start blinking cursor (IGNORED) */
768 break; 760 break;
769 case 25: 761 case 25:
770 term.hidec = 0; 762 term.c.hide = 0;
771 break; 763 break;
772 case 1048: 764 case 1048:
773 case 1049: /* XXX: no alt. screen to erase/save */ 765 case 1049: /* XXX: no alt. screen to erase/save */
@@ -1173,7 +1165,7 @@ draw(int dummy) {
1173 if(term.line[y][x].state & GLYPH_SET) 1165 if(term.line[y][x].state & GLYPH_SET)
1174 xdrawc(x, y, term.line[y][x]); 1166 xdrawc(x, y, term.line[y][x]);
1175 1167
1176 if(!term.hidec) 1168 if(!term.c.hide)
1177 xcursor(CURSOR_DRAW); 1169 xcursor(CURSOR_DRAW);
1178 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); 1170 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER);
1179 XFlush(xw.dis); 1171 XFlush(xw.dis);
@@ -1206,7 +1198,7 @@ draw(int redraw_all) {
1206 } 1198 }
1207 xdraws(buf, base, ox, y, i); 1199 xdraws(buf, base, ox, y, i);
1208 } 1200 }
1209 xcursor(term.hidec ? CURSOR_HIDE : CURSOR_DRAW); 1201 xcursor(term.c.hide ? CURSOR_HIDE : CURSOR_DRAW);
1210 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); 1202 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER);
1211 XFlush(xw.dis); 1203 XFlush(xw.dis);
1212} 1204}