X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=5715f0fc0d675c4a234f01792bc22476b5f1518d;hb=10e49a0505a250fc78c41842d93eb2a0abaf4c93;hp=a571a28ed329f494016c19786020fbc609ac087c;hpb=2f96cfeadaac871456e2e2acae3b997c23c93d63;p=st.git diff --git a/st.c b/st.c old mode 100755 new mode 100644 index a571a28..5715f0f --- a/st.c +++ b/st.c @@ -20,7 +20,7 @@ #include #include -#define TNAME "xterm" +#define TNAME "st-256color" /* Arbitrary sizes */ #define ESC_TITLE_SIZ 256 @@ -111,7 +111,7 @@ typedef struct { /* Drawing Context */ typedef struct { - unsigned long col[LEN(colorname)]; + unsigned long col[256]; XFontStruct* font; XFontStruct* bfont; GC gc; @@ -154,7 +154,6 @@ static void ttyread(void); static void ttyresize(int, int); static void ttywrite(const char *, size_t); -static unsigned long xgetcol(const char *); static void xclear(int, int, int, int); static void xcursor(int); static void xinit(void); @@ -593,19 +592,45 @@ tsetattr(int *attr, int l) { case 27: term.c.attr.mode &= ~ATTR_REVERSE; break; + case 38: + if (i + 2 < l && attr[i + 1] == 5) { + i += 2; + if (BETWEEN(attr[i], 0, 255)) + term.c.attr.fg = attr[i]; + else + fprintf(stderr, "erresc: bad fgcolor %d\n", attr[i]); + } + else + fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]); + break; case 39: term.c.attr.fg = DefaultFG; break; + case 48: + if (i + 2 < l && attr[i + 1] == 5) { + i += 2; + if (BETWEEN(attr[i], 0, 255)) + term.c.attr.bg = attr[i]; + else + fprintf(stderr, "erresc: bad bgcolor %d\n", attr[i]); + } + else + fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]); + break; case 49: - term.c.attr.fg = DefaultBG; + term.c.attr.bg = DefaultBG; break; default: if(BETWEEN(attr[i], 30, 37)) term.c.attr.fg = attr[i] - 30; else if(BETWEEN(attr[i], 40, 47)) term.c.attr.bg = attr[i] - 40; + else if(BETWEEN(attr[i], 90, 97)) + term.c.attr.fg = attr[i] - 90 + 8; + else if(BETWEEN(attr[i], 100, 107)) + term.c.attr.fg = attr[i] - 100 + 8; else - fprintf(stderr, "erresc: gfx attr %d unkown\n", attr[i]); + fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]); break; } } @@ -1009,16 +1034,44 @@ tresize(int col, int row) { term.col = col, term.row = row; } -unsigned long -xgetcol(const char *s) { +void +tloadcols(void) { + int i, r, g, b; XColor color; Colormap cmap = DefaultColormap(xw.dis, xw.scr); + unsigned long white = WhitePixel(xw.dis, xw.scr); + + for(i = 0; i < 16; i++) { + if (!XAllocNamedColor(xw.dis, cmap, colorname[i], &color, &color)) { + dc.col[i] = white; + fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]); + } else + dc.col[i] = color.pixel; + } + + /* same colors as xterm */ + for(r = 0; r < 6; r++) + for(g = 0; g < 6; g++) + for(b = 0; b < 6; b++) { + color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r; + color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g; + color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b; + if (!XAllocColor(xw.dis, cmap, &color)) { + dc.col[i] = white; + fprintf(stderr, "Could not allocate color %d\n", i); + } else + dc.col[i] = color.pixel; + i++; + } - if(!XAllocNamedColor(xw.dis, cmap, s, &color, &color)) { - color.pixel = WhitePixel(xw.dis, xw.scr); - fprintf(stderr, "Could not allocate color '%s'\n", s); + for(r = 0; r < 24; r++, i++) { + color.red = color.green = color.blue = 0x0808 + 0x0a0a * r; + if (!XAllocColor(xw.dis, cmap, &color)) { + dc.col[i] = white; + fprintf(stderr, "Could not allocate color %d\n", i); + } else + dc.col[i] = color.pixel; } - return color.pixel; } void @@ -1032,9 +1085,9 @@ xclear(int x1, int y1, int x2, int y2) { void xhints(void) { - XClassHint chint = {TNAME, TNAME}; - XWMHints wmhint = {.flags = InputHint, .input = 1}; - XSizeHints shint = { + XClassHint class = {TNAME, TNAME}; + XWMHints wm = {.flags = InputHint, .input = 1}; + XSizeHints size = { .flags = PSize | PResizeInc | PBaseSize, .height = xw.h, .width = xw.w, @@ -1043,13 +1096,11 @@ xhints(void) .base_height = 2*BORDER, .base_width = 2*BORDER, }; - XSetWMProperties(xw.dis, xw.win, NULL, NULL, NULL, 0, &shint, &wmhint, &chint); + XSetWMProperties(xw.dis, xw.win, NULL, NULL, NULL, 0, &size, &wm, &class); } void xinit(void) { - int i; - xw.dis = XOpenDisplay(NULL); xw.scr = XDefaultScreen(xw.dis); if(!xw.dis) @@ -1064,8 +1115,7 @@ xinit(void) { xw.ch = dc.font->ascent + dc.font->descent; /* colors */ - for(i = 0; i < LEN(colorname); i++) - dc.col[i] = xgetcol(colorname[i]); + tloadcols(); term.c.attr.fg = DefaultFG; term.c.attr.bg = DefaultBG; @@ -1104,7 +1154,7 @@ xdraws(char *s, Glyph base, int x, int y, int len) { if(base.mode & ATTR_GFX) for(i = 0; i < len; i++) - s[i] = gfx[s[i]]; + s[i] = gfx[(int)s[i]]; XSetFont(xw.dis, dc.gc, base.mode & ATTR_BOLD ? dc.bfont->fid : dc.font->fid); XDrawImageString(xw.dis, xw.buf, dc.gc, winx, winy, s, len); @@ -1173,6 +1223,8 @@ draw(int redraw_all) { Glyph base, new; char buf[DRAW_BUF_SIZ]; + XSetForeground(xw.dis, dc.gc, dc.col[DefaultBG]); + XFillRectangle(xw.dis, xw.buf, dc.gc, 0, 0, xw.w, xw.h); for(y = 0; y < term.row; y++) { base = term.line[y][0]; i = ox = 0; @@ -1225,7 +1277,7 @@ kpress(XEvent *ev) { shift = e->state & ShiftMask; len = XLookupString(e, buf, sizeof(buf), &ksym, NULL); - if(customkey = kmap(ksym)) + if((customkey = kmap(ksym))) ttywrite(customkey, strlen(customkey)); else if(len > 0) { buf[sizeof(buf)-1] = '\0';