applied Devin J Pohly's st color info patches, thanks Devin!

This commit is contained in:
Anselm R Garbe 2010-07-24 12:09:14 +01:00
parent 9e8f5f1348
commit 10e49a0505
4 changed files with 88 additions and 27 deletions

View file

@ -42,6 +42,7 @@ install: all
@cp -f st ${DESTDIR}${PREFIX}/bin @cp -f st ${DESTDIR}${PREFIX}/bin
@chmod 755 ${DESTDIR}${PREFIX}/bin/st @chmod 755 ${DESTDIR}${PREFIX}/bin/st
@tic st.info @tic st.info
@tic st-256color.info
uninstall: uninstall:
@echo removing executable file from ${DESTDIR}${PREFIX}/bin @echo removing executable file from ${DESTDIR}${PREFIX}/bin

View file

@ -7,13 +7,21 @@
/* Terminal colors */ /* Terminal colors */
static const char *colorname[] = { static const char *colorname[] = {
"black", "black",
"red", "#CC0000",
"green", "#4E9A06",
"yellow", "#C4A000",
"blue", "#3465A4",
"magenta", "#75507B",
"cyan", "#06989A",
"white", "#888a85",
"#555753",
"#EF2929",
"#8AE234",
"#FCE94F",
"#729FCF",
"#AD7FA8",
"#34E2E2",
"#EEEEEC"
}; };
/* Default colors (colorname index) */ /* Default colors (colorname index) */

80
st.c Executable file → Normal file
View file

@ -20,7 +20,7 @@
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#define TNAME "xterm" #define TNAME "st-256color"
/* Arbitrary sizes */ /* Arbitrary sizes */
#define ESC_TITLE_SIZ 256 #define ESC_TITLE_SIZ 256
@ -111,7 +111,7 @@ typedef struct {
/* Drawing Context */ /* Drawing Context */
typedef struct { typedef struct {
unsigned long col[LEN(colorname)]; unsigned long col[256];
XFontStruct* font; XFontStruct* font;
XFontStruct* bfont; XFontStruct* bfont;
GC gc; GC gc;
@ -154,7 +154,6 @@ static void ttyread(void);
static void ttyresize(int, int); static void ttyresize(int, int);
static void ttywrite(const char *, size_t); static void ttywrite(const char *, size_t);
static unsigned long xgetcol(const char *);
static void xclear(int, int, int, int); static void xclear(int, int, int, int);
static void xcursor(int); static void xcursor(int);
static void xinit(void); static void xinit(void);
@ -593,9 +592,31 @@ tsetattr(int *attr, int l) {
case 27: case 27:
term.c.attr.mode &= ~ATTR_REVERSE; term.c.attr.mode &= ~ATTR_REVERSE;
break; 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: case 39:
term.c.attr.fg = DefaultFG; term.c.attr.fg = DefaultFG;
break; 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: case 49:
term.c.attr.bg = DefaultBG; term.c.attr.bg = DefaultBG;
break; break;
@ -604,8 +625,12 @@ tsetattr(int *attr, int l) {
term.c.attr.fg = attr[i] - 30; term.c.attr.fg = attr[i] - 30;
else if(BETWEEN(attr[i], 40, 47)) else if(BETWEEN(attr[i], 40, 47))
term.c.attr.bg = attr[i] - 40; 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 else
fprintf(stderr, "erresc: gfx attr %d unkown\n", attr[i]); fprintf(stderr, "erresc: gfx attr %d unknown\n", attr[i]);
break; break;
} }
} }
@ -1009,16 +1034,44 @@ tresize(int col, int row) {
term.col = col, term.row = row; term.col = col, term.row = row;
} }
unsigned long void
xgetcol(const char *s) { tloadcols(void) {
int i, r, g, b;
XColor color; XColor color;
Colormap cmap = DefaultColormap(xw.dis, xw.scr); Colormap cmap = DefaultColormap(xw.dis, xw.scr);
unsigned long white = WhitePixel(xw.dis, xw.scr);
if(!XAllocNamedColor(xw.dis, cmap, s, &color, &color)) { for(i = 0; i < 16; i++) {
color.pixel = WhitePixel(xw.dis, xw.scr); if (!XAllocNamedColor(xw.dis, cmap, colorname[i], &color, &color)) {
fprintf(stderr, "Could not allocate color '%s'\n", s); 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++;
}
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 void
@ -1048,8 +1101,6 @@ xhints(void)
void void
xinit(void) { xinit(void) {
int i;
xw.dis = XOpenDisplay(NULL); xw.dis = XOpenDisplay(NULL);
xw.scr = XDefaultScreen(xw.dis); xw.scr = XDefaultScreen(xw.dis);
if(!xw.dis) if(!xw.dis)
@ -1064,8 +1115,7 @@ xinit(void) {
xw.ch = dc.font->ascent + dc.font->descent; xw.ch = dc.font->ascent + dc.font->descent;
/* colors */ /* colors */
for(i = 0; i < LEN(colorname); i++) tloadcols();
dc.col[i] = xgetcol(colorname[i]);
term.c.attr.fg = DefaultFG; term.c.attr.fg = DefaultFG;
term.c.attr.bg = DefaultBG; term.c.attr.bg = DefaultBG;
@ -1173,6 +1223,8 @@ draw(int redraw_all) {
Glyph base, new; Glyph base, new;
char buf[DRAW_BUF_SIZ]; 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++) { for(y = 0; y < term.row; y++) {
base = term.line[y][0]; base = term.line[y][0];
i = ox = 0; i = ox = 0;

12
st.info
View file

@ -1,7 +1,6 @@
# Reconstructed via infocmp from file: /lib/terminfo/p/pcansi
st| simpleterm, st| simpleterm,
am, am,
ul, ul,
mir, mir,
msgr, msgr,
colors#8, colors#8,
@ -10,7 +9,7 @@ st| simpleterm,
lines#24, lines#24,
ncv#3, ncv#3,
pairs#64, 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, bel=^G,
bold=\E[1m, bold=\E[1m,
cbt=\E[Z, cbt=\E[Z,
@ -36,9 +35,11 @@ st| simpleterm,
kcud1=\E[B, kcud1=\E[B,
kcuf1=\E[C, kcuf1=\E[C,
kcuu1=\E[A, kcuu1=\E[A,
kdch1=\E[3~,
kend=\E[4~,
khome=\E[1~, khome=\E[1~,
knp=\E[6~, knp=\E[6~,
kpp=\E[5~, kpp=\E[5~,
op=\E[37;40m, op=\E[37;40m,
rev=\E[7m, rev=\E[7m,
rmacs=\E[10m, rmacs=\E[10m,
@ -46,7 +47,6 @@ st| simpleterm,
rmul=\E[m, rmul=\E[m,
setab=\E[4%p1%dm, setab=\E[4%p1%dm,
setaf=\E[3%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, sgr0=\E[0m,
smacs=\E[12m, smacs=\E[12m,
smso=\E[7m, smso=\E[7m,