applied Devin J Pohly's st color info patches, thanks Devin!
authorAnselm R Garbe <anselm@garbe.us>
Sat, 24 Jul 2010 11:09:14 +0000 (12:09 +0100)
committerAnselm R Garbe <anselm@garbe.us>
Sat, 24 Jul 2010 11:09:14 +0000 (12:09 +0100)
Makefile
config.h
st.c [changed mode: 0755->0644]
st.info

index 9ec8d21..14da7a5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -42,6 +42,7 @@ install: all
        @cp -f st ${DESTDIR}${PREFIX}/bin
        @chmod 755 ${DESTDIR}${PREFIX}/bin/st
        @tic st.info
+       @tic st-256color.info
 
 uninstall:
        @echo removing executable file from ${DESTDIR}${PREFIX}/bin
index 0b0b36d..aee8057 100644 (file)
--- a/config.h
+++ b/config.h
@@ -7,13 +7,21 @@
 /* Terminal colors */
 static const char *colorname[] = {
        "black",
-       "red",
-       "green",
-       "yellow",
-       "blue",
-       "magenta",
-       "cyan",
-       "white",
+       "#CC0000",
+       "#4E9A06",
+       "#C4A000",
+       "#3465A4",
+       "#75507B",
+       "#06989A",
+       "#888a85",
+       "#555753",
+       "#EF2929",
+       "#8AE234",
+       "#FCE94F",
+       "#729FCF",
+       "#AD7FA8",
+       "#34E2E2",
+       "#EEEEEC"
 };
 
 /* Default colors (colorname index) */
diff --git a/st.c b/st.c
old mode 100755 (executable)
new mode 100644 (file)
index c64c25e..5715f0f
--- a/st.c
+++ b/st.c
@@ -20,7 +20,7 @@
 #include <X11/keysym.h>
 #include <X11/Xutil.h>
 
-#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,9 +592,31 @@ 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.bg = DefaultBG;
                        break;
@@ -604,8 +625,12 @@ tsetattr(int *attr, int l) {
                                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
@@ -1048,8 +1101,6 @@ xhints(void)
 
 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;
@@ -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;
diff --git a/st.info b/st.info
index 1ded6b5..1cf6344 100644 (file)
--- a/st.info
+++ b/st.info
@@ -1,7 +1,6 @@
-#      Reconstructed via infocmp from file: /lib/terminfo/p/pcansi
 st| simpleterm,
        am,
-    ul,
+       ul,
        mir,
        msgr,
        colors#8,
@@ -10,7 +9,7 @@ st| simpleterm,
        lines#24,
        ncv#3,
        pairs#64,
-    acsc=*`#aof+g+j+k+l+m+n-o-p-q-r-s+t+u+v+w|x<y>z{{||}}-~,
+       acsc=*`#aof+g+j+k+l+m+n-o-p-q-r-s+t+u+v+w|x<y>z{{||}}-~,
        bel=^G,
        bold=\E[1m,
        cbt=\E[Z,
@@ -36,9 +35,11 @@ st| simpleterm,
        kcud1=\E[B,
        kcuf1=\E[C,
        kcuu1=\E[A,
+       kdch1=\E[3~,
+       kend=\E[4~,
        khome=\E[1~,
-    knp=\E[6~,
-    kpp=\E[5~,
+       knp=\E[6~,
+       kpp=\E[5~,
        op=\E[37;40m,
        rev=\E[7m,
        rmacs=\E[10m,
@@ -46,7 +47,6 @@ st| simpleterm,
        rmul=\E[m,
        setab=\E[4%p1%dm,
        setaf=\E[3%p1%dm,
-#      sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;12%;m,
        sgr0=\E[0m,
        smacs=\E[12m,
        smso=\E[7m,