[hackers] [st] applied Devin J Pohly's st color info patches, thanks Devin! || Anselm R Garbe

From: <hg_AT_suckless.org>
Date: Sat, 24 Jul 2010 11:09:07 +0000 (UTC)

changeset: 84:6dd2644c9715
tag: tip
user: Anselm R Garbe <anselm_AT_garbe.us>
date: Sat Jul 24 12:09:14 2010 +0100
files: Makefile config.h st.c st.info
description:
applied Devin J Pohly's st color info patches, thanks Devin!

diff -r 30a6475eff94 -r 6dd2644c9715 Makefile
--- a/Makefile Thu Jul 08 17:34:02 2010 +0200
+++ b/Makefile Sat Jul 24 12:09:14 2010 +0100
@@ -42,6 +42,7 @@
         @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
diff -r 30a6475eff94 -r 6dd2644c9715 config.h
--- a/config.h Thu Jul 08 17:34:02 2010 +0200
+++ b/config.h Sat Jul 24 12:09:14 2010 +0100
@@ -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 -r 30a6475eff94 -r 6dd2644c9715 st.c
--- a/st.c Thu Jul 08 17:34:02 2010 +0200
+++ b/st.c Sat Jul 24 12:09:14 2010 +0100
@@ -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 @@
 
 /* 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 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 @@
                 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 @@
                                 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 @@
         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);
 
- 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(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;
         }
- return 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++;
+ }
+
+ 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;
+ }
 }
 
 void
@@ -1048,8 +1101,6 @@
 
 void
 xinit(void) {
- int i;
-
         xw.dis = XOpenDisplay(NULL);
         xw.scr = XDefaultScreen(xw.dis);
         if(!xw.dis)
@@ -1064,8 +1115,7 @@
         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 @@
         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 -r 30a6475eff94 -r 6dd2644c9715 st.info
--- a/st.info Thu Jul 08 17:34:02 2010 +0200
+++ b/st.info Sat Jul 24 12:09:14 2010 +0100
@@ -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 @@
         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 @@
         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 @@
         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,
Received on Sat Jul 24 2010 - 13:09:07 CEST

This archive was generated by hypermail 2.2.0 : Sat Jul 24 2010 - 13:12:03 CEST