aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
Diffstat (limited to 'st.c')
-rw-r--r--[-rwxr-xr-x]st.c80
1 files changed, 66 insertions, 14 deletions
diff --git a/st.c b/st.c
index c64c25e..5715f0f 100755..100644
--- a/st.c
+++ b/st.c
@@ -20,7 +20,7 @@
20#include <X11/keysym.h> 20#include <X11/keysym.h>
21#include <X11/Xutil.h> 21#include <X11/Xutil.h>
22 22
23#define TNAME "xterm" 23#define TNAME "st-256color"
24 24
25/* Arbitrary sizes */ 25/* Arbitrary sizes */
26#define ESC_TITLE_SIZ 256 26#define ESC_TITLE_SIZ 256
@@ -111,7 +111,7 @@ typedef struct {
111 111
112/* Drawing Context */ 112/* Drawing Context */
113typedef struct { 113typedef struct {
114 unsigned long col[LEN(colorname)]; 114 unsigned long col[256];
115 XFontStruct* font; 115 XFontStruct* font;
116 XFontStruct* bfont; 116 XFontStruct* bfont;
117 GC gc; 117 GC gc;
@@ -154,7 +154,6 @@ static void ttyread(void);
154static void ttyresize(int, int); 154static void ttyresize(int, int);
155static void ttywrite(const char *, size_t); 155static void ttywrite(const char *, size_t);
156 156
157static unsigned long xgetcol(const char *);
158static void xclear(int, int, int, int); 157static void xclear(int, int, int, int);
159static void xcursor(int); 158static void xcursor(int);
160static void xinit(void); 159static void xinit(void);
@@ -593,9 +592,31 @@ tsetattr(int *attr, int l) {
593 case 27: 592 case 27:
594 term.c.attr.mode &= ~ATTR_REVERSE; 593 term.c.attr.mode &= ~ATTR_REVERSE;
595 break; 594 break;
595 case 38:
596 if (i + 2 < l && attr[i + 1] == 5) {
597 i += 2;
598 if (BETWEEN(attr[i], 0, 255))
599 term.c.attr.fg = attr[i];
600 else
601 fprintf(stderr, "erresc: bad fgcolor %d\n", attr[i]);
602 }
603 else
604 fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]);
605 break;
596 case 39: 606 case 39:
597 term.c.attr.fg = DefaultFG; 607 term.c.attr.fg = DefaultFG;
598 break; 608 break;
609 case 48:
610 if (i + 2 < l && attr[i + 1] == 5) {
611 i += 2;
612 if (BETWEEN(attr[i], 0, 255))
613 term.c.attr.bg = attr[i];
614 else
615 fprintf(stderr, "erresc: bad bgcolor %d\n", attr[i]);
616 }
617 else
618 fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]);
619 break;
599 case 49: 620 case 49:
600 term.c.attr.bg = DefaultBG; 621 term.c.attr.bg = DefaultBG;
601 break; 622 break;
@@ -604,8 +625,12 @@ tsetattr(int *attr, int l) {
604 term.c.attr.fg = attr[i] - 30; 625 term.c.attr.fg = attr[i] - 30;
605 else if(BETWEEN(attr[i], 40, 47)) 626 else if(BETWEEN(attr[i], 40, 47))
606 term.c.attr.bg = attr[i] - 40; 627 term.c.attr.bg = attr[i] - 40;
628 else if(BETWEEN(attr[i], 90, 97))
629 term.c.attr.fg = attr[i] - 90 + 8;
630 else if(BETWEEN(attr[i], 100, 107))
631 term.c.attr.fg = attr[i] - 100 + 8;
607 else 632 else
608 fprintf(stderr, "erresc: gfx attr %d unkown\n", attr[i]); 633 fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]);
609 break; 634 break;
610 } 635 }
611 } 636 }
@@ -1009,16 +1034,44 @@ tresize(int col, int row) {
1009 term.col = col, term.row = row; 1034 term.col = col, term.row = row;
1010} 1035}
1011 1036
1012unsigned long 1037void
1013xgetcol(const char *s) { 1038tloadcols(void) {
1039 int i, r, g, b;
1014 XColor color; 1040 XColor color;
1015 Colormap cmap = DefaultColormap(xw.dis, xw.scr); 1041 Colormap cmap = DefaultColormap(xw.dis, xw.scr);
1042 unsigned long white = WhitePixel(xw.dis, xw.scr);
1043
1044 for(i = 0; i < 16; i++) {
1045 if (!XAllocNamedColor(xw.dis, cmap, colorname[i], &color, &color)) {
1046 dc.col[i] = white;
1047 fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]);
1048 } else
1049 dc.col[i] = color.pixel;
1050 }
1051
1052 /* same colors as xterm */
1053 for(r = 0; r < 6; r++)
1054 for(g = 0; g < 6; g++)
1055 for(b = 0; b < 6; b++) {
1056 color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r;
1057 color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g;
1058 color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b;
1059 if (!XAllocColor(xw.dis, cmap, &color)) {
1060 dc.col[i] = white;
1061 fprintf(stderr, "Could not allocate color %d\n", i);
1062 } else
1063 dc.col[i] = color.pixel;
1064 i++;
1065 }
1016 1066
1017 if(!XAllocNamedColor(xw.dis, cmap, s, &color, &color)) { 1067 for(r = 0; r < 24; r++, i++) {
1018 color.pixel = WhitePixel(xw.dis, xw.scr); 1068 color.red = color.green = color.blue = 0x0808 + 0x0a0a * r;
1019 fprintf(stderr, "Could not allocate color '%s'\n", s); 1069 if (!XAllocColor(xw.dis, cmap, &color)) {
1070 dc.col[i] = white;
1071 fprintf(stderr, "Could not allocate color %d\n", i);
1072 } else
1073 dc.col[i] = color.pixel;
1020 } 1074 }
1021 return color.pixel;
1022} 1075}
1023 1076
1024void 1077void
@@ -1048,8 +1101,6 @@ xhints(void)
1048 1101
1049void 1102void
1050xinit(void) { 1103xinit(void) {
1051 int i;
1052
1053 xw.dis = XOpenDisplay(NULL); 1104 xw.dis = XOpenDisplay(NULL);
1054 xw.scr = XDefaultScreen(xw.dis); 1105 xw.scr = XDefaultScreen(xw.dis);
1055 if(!xw.dis) 1106 if(!xw.dis)
@@ -1064,8 +1115,7 @@ xinit(void) {
1064 xw.ch = dc.font->ascent + dc.font->descent; 1115 xw.ch = dc.font->ascent + dc.font->descent;
1065 1116
1066 /* colors */ 1117 /* colors */
1067 for(i = 0; i < LEN(colorname); i++) 1118 tloadcols();
1068 dc.col[i] = xgetcol(colorname[i]);
1069 1119
1070 term.c.attr.fg = DefaultFG; 1120 term.c.attr.fg = DefaultFG;
1071 term.c.attr.bg = DefaultBG; 1121 term.c.attr.bg = DefaultBG;
@@ -1173,6 +1223,8 @@ draw(int redraw_all) {
1173 Glyph base, new; 1223 Glyph base, new;
1174 char buf[DRAW_BUF_SIZ]; 1224 char buf[DRAW_BUF_SIZ];
1175 1225
1226 XSetForeground(xw.dis, dc.gc, dc.col[DefaultBG]);
1227 XFillRectangle(xw.dis, xw.buf, dc.gc, 0, 0, xw.w, xw.h);
1176 for(y = 0; y < term.row; y++) { 1228 for(y = 0; y < term.row; y++) {
1177 base = term.line[y][0]; 1229 base = term.line[y][0];
1178 i = ox = 0; 1230 i = ox = 0;