X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=e6a5e4ea32d35fd70b74bc0d45016c18d674747e;hb=751fb765e4f26ce1500b4e8ee9f4cd5b6039b495;hp=98cd78ac81ba3f1862960ce8b77bada5d9adeffa;hpb=cee6ccc6ee21fb6a4e4e04c2727aec26b7d47e07;p=st.git diff --git a/st.c b/st.c index 98cd78a..e6a5e4e 100644 --- a/st.c +++ b/st.c @@ -34,7 +34,7 @@ #endif #define USAGE \ - "st " VERSION " (c) 2010-2011 st engineers\n" \ + "st " VERSION " (c) 2010-2012 st engineers\n" \ "usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n" /* XEMBED messages */ @@ -83,13 +83,14 @@ enum { B0=1, B1=2, B2=4, B3=8, B4=16, B5=32, B6=64, B7=128 }; typedef unsigned char uchar; typedef unsigned int uint; typedef unsigned long ulong; +typedef unsigned short ushort; typedef struct { char c[UTF_SIZ]; /* character code */ uchar mode; /* attribute flags */ - uchar fg; /* foreground */ - uchar bg; /* background */ - uchar state; /* state flags */ + ushort fg; /* foreground */ + ushort bg; /* background */ + uchar state; /* state flags */ } Glyph; typedef Glyph* Line; @@ -154,18 +155,6 @@ typedef struct { char s[ESC_BUF_SIZ]; } Key; -/* Drawing Context */ -typedef struct { - ulong col[256]; - GC gc; - struct { - int ascent; - int descent; - short lbearing; - short rbearing; - XFontSet set; - } font, bfont; -} DC; /* TODO: use better name for vars... */ typedef struct { @@ -181,6 +170,19 @@ typedef struct { #include "config.h" +/* Drawing Context */ +typedef struct { + ulong col[LEN(colorname) < 256 ? 256 : LEN(colorname)]; + GC gc; + struct { + int ascent; + int descent; + short lbearing; + short rbearing; + XFontSet set; + } font, bfont; +} DC; + static void die(const char*, ...); static void draw(void); static void drawregion(int, int, int, int); @@ -1341,14 +1343,8 @@ csihandle(void) { void csidump(void) { - int i; - printf("ESC [ %s", escseq.priv ? "? " : ""); - if(escseq.narg) - for(i = 0; i < escseq.narg; i++) - printf("%d ", escseq.arg[i]); - if(escseq.mode) - putchar(escseq.mode); - putchar('\n'); + fwrite("\033[", 1, 2, stdout); + fwrite(escseq.buf, 1, escseq.len, stdout); } void @@ -1589,16 +1585,19 @@ xloadcols(void) { XColor color; ulong white = WhitePixel(xw.dpy, xw.scr); + /* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */ for(i = 0; i < LEN(colorname); i++) { + if(!colorname[i]) + continue; if(!XAllocNamedColor(xw.dpy, xw.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++) + + /* load colors [16-255] ; same colors as xterm */ + for(i = 16, 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; @@ -1761,23 +1760,29 @@ xinit(void) { void xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { - ulong xfg = dc.col[base.fg], xbg = dc.col[base.bg], temp; + int fg = base.fg, bg = base.bg, temp; int winx = x*xw.cw, winy = y*xw.ch + dc.font.ascent, width = charlen*xw.cw; + XFontSet fontset = dc.font.set; int i; /* only switch default fg/bg if term is in RV mode */ if(IS_SET(MODE_REVERSE)) { - if(base.fg == DefaultFG) - xfg = dc.col[DefaultBG]; - if(base.bg == DefaultBG) - xbg = dc.col[DefaultFG]; + if(fg == DefaultFG) + fg = DefaultBG; + if(bg == DefaultBG) + bg = DefaultFG; } if(base.mode & ATTR_REVERSE) - temp = xfg, xfg = xbg, xbg = temp; + temp = fg, fg = bg, bg = temp; + + if(base.mode & ATTR_BOLD) { + fg += 8; + fontset = dc.bfont.set; + } - XSetBackground(xw.dpy, dc.gc, xbg); - XSetForeground(xw.dpy, dc.gc, xfg); + XSetBackground(xw.dpy, dc.gc, dc.col[bg]); + XSetForeground(xw.dpy, dc.gc, dc.col[fg]); if(base.mode & ATTR_GFX) { for(i = 0; i < bytelen; i++) { @@ -1789,8 +1794,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { } } - XmbDrawImageString(xw.dpy, xw.buf, base.mode & ATTR_BOLD ? dc.bfont.set : dc.font.set, - dc.gc, winx, winy, s, bytelen); + XmbDrawImageString(xw.dpy, xw.buf, fontset, dc.gc, winx, winy, s, bytelen); if(base.mode & ATTR_UNDERLINE) XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1); @@ -1827,10 +1831,14 @@ xdrawcursor(void) { xcopy(oldx, oldy, 1, 1); /* draw the new one */ - if(!(term.c.state & CURSOR_HIDE) && (xw.state & WIN_FOCUSED)) { - sl = utf8size(g.c); + if(!(term.c.state & CURSOR_HIDE)) { + if(!(xw.state & WIN_FOCUSED)) + g.bg = DefaultUCS; + if(IS_SET(MODE_REVERSE)) g.mode |= ATTR_REVERSE, g.fg = DefaultCS, g.bg = DefaultFG; + + sl = utf8size(g.c); xdraws(g.c, g, term.c.x, term.c.y, 1, sl); oldx = term.c.x, oldy = term.c.y; }