Patch: Solarized

This commit is contained in:
Martin Potier 2019-02-15 17:05:15 +02:00
parent e85b6b6466
commit ad845fbc91
3 changed files with 69 additions and 34 deletions

View file

@ -84,31 +84,44 @@ unsigned int tabspaces = 8;
/* Terminal colors (16 first used in escape sequence) */ /* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = { static const char *colorname[] = {
/* 8 normal colors */ /* solarized dark */
"black", "#073642", /* 0: black */
"red3", "#dc322f", /* 1: red */
"green3", "#859900", /* 2: green */
"yellow3", "#b58900", /* 3: yellow */
"blue2", "#268bd2", /* 4: blue */
"magenta3", "#d33682", /* 5: magenta */
"cyan3", "#2aa198", /* 6: cyan */
"gray90", "#eee8d5", /* 7: white */
"#002b36", /* 8: brblack */
"#cb4b16", /* 9: brred */
"#586e75", /* 10: brgreen */
"#657b83", /* 11: bryellow */
"#839496", /* 12: brblue */
"#6c71c4", /* 13: brmagenta*/
"#93a1a1", /* 14: brcyan */
"#fdf6e3", /* 15: brwhite */
};
/* 8 bright colors */ /* Terminal colors for alternate (light) palette */
"gray50", static const char *altcolorname[] = {
"red", /* solarized light */
"green", "#eee8d5", /* 0: black */
"yellow", "#dc322f", /* 1: red */
"#5c5cff", "#859900", /* 2: green */
"magenta", "#b58900", /* 3: yellow */
"cyan", "#268bd2", /* 4: blue */
"white", "#d33682", /* 5: magenta */
"#2aa198", /* 6: cyan */
[255] = 0, "#073642", /* 7: white */
"#fdf6e3", /* 8: brblack */
/* more colors can be added after 255 to use with DefaultXX */ "#cb4b16", /* 9: brred */
"#cccccc", "#93a1a1", /* 10: brgreen */
"#555555", "#839496", /* 11: bryellow */
"#657b83", /* 12: brblue */
"#6c71c4", /* 13: brmagenta*/
"#586e75", /* 14: brcyan */
"#002b36", /* 15: brwhite */
}; };
@ -116,10 +129,10 @@ static const char *colorname[] = {
* Default colors (colorname index) * Default colors (colorname index)
* foreground, background, cursor, reverse cursor * foreground, background, cursor, reverse cursor
*/ */
unsigned int defaultfg = 7; unsigned int defaultfg = 12;
unsigned int defaultbg = 0; unsigned int defaultbg = 8;
static unsigned int defaultcs = 256; static unsigned int defaultcs = 14;
static unsigned int defaultrcs = 257; static unsigned int defaultrcs = 15;
/* /*
* Default shape of cursor * Default shape of cursor
@ -178,6 +191,8 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_Y, selpaste, {.i = 0} }, { TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} }, { ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ TERMMOD, XK_I, iso14755, {.i = 0} },
{ XK_ANY_MOD, XK_F6, swapcolors, {.i = 0} },
}; };
/* /*

1
st.h
View file

@ -117,6 +117,7 @@ extern char *vtiden;
extern char *worddelimiters; extern char *worddelimiters;
extern int allowaltscreen; extern int allowaltscreen;
extern char *termname; extern char *termname;
extern int usealtcolors;
extern unsigned int tabspaces; extern unsigned int tabspaces;
extern unsigned int defaultfg; extern unsigned int defaultfg;
extern unsigned int defaultbg; extern unsigned int defaultbg;

29
x.c
View file

@ -53,6 +53,7 @@ static void clipcopy(const Arg *);
static void clippaste(const Arg *); static void clippaste(const Arg *);
static void numlock(const Arg *); static void numlock(const Arg *);
static void selpaste(const Arg *); static void selpaste(const Arg *);
static void swapcolors(const Arg *);
static void zoom(const Arg *); static void zoom(const Arg *);
static void zoomabs(const Arg *); static void zoomabs(const Arg *);
static void zoomreset(const Arg *); static void zoomreset(const Arg *);
@ -243,6 +244,8 @@ static char *opt_title = NULL;
static int oldbutton = 3; /* button event on startup: 3 = release */ static int oldbutton = 3; /* button event on startup: 3 = release */
int usealtcolors = 0; /* 1 to use alternate palette */
void void
clipcopy(const Arg *dummy) clipcopy(const Arg *dummy)
{ {
@ -281,6 +284,14 @@ numlock(const Arg *dummy)
win.mode ^= MODE_NUMLOCK; win.mode ^= MODE_NUMLOCK;
} }
void
swapcolors(const Arg *dummy)
{
usealtcolors = !usealtcolors;
xloadcols();
redraw();
}
void void
zoom(const Arg *arg) zoom(const Arg *arg)
{ {
@ -705,6 +716,11 @@ sixd_to_16bit(int x)
return x == 0 ? 0 : 0x3737 + 0x2828 * x; return x == 0 ? 0 : 0x3737 + 0x2828 * x;
} }
const char* getcolorname(int i)
{
return (usealtcolors) ? altcolorname[i] : colorname[i];
}
int int
xloadcolor(int i, const char *name, Color *ncolor) xloadcolor(int i, const char *name, Color *ncolor)
{ {
@ -723,7 +739,7 @@ xloadcolor(int i, const char *name, Color *ncolor)
return XftColorAllocValue(xw.dpy, xw.vis, return XftColorAllocValue(xw.dpy, xw.vis,
xw.cmap, &color, ncolor); xw.cmap, &color, ncolor);
} else } else
name = colorname[i]; name = getcolorname(i);
} }
return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
@ -736,6 +752,9 @@ xloadcols(void)
static int loaded; static int loaded;
Color *cp; Color *cp;
dc.collen = MAX(LEN(colorname), LEN(altcolorname));
dc.col = xmalloc(dc.collen * sizeof(Color));
if (loaded) { if (loaded) {
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp) for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
@ -746,8 +765,8 @@ xloadcols(void)
for (i = 0; i < dc.collen; i++) for (i = 0; i < dc.collen; i++)
if (!xloadcolor(i, NULL, &dc.col[i])) { if (!xloadcolor(i, NULL, &dc.col[i])) {
if (colorname[i]) if (getcolorname(i))
die("could not allocate color '%s'\n", colorname[i]); die("Could not allocate color '%s'\n", getcolorname(i));
else else
die("could not allocate color %d\n", i); die("could not allocate color %d\n", i);
} }
@ -1107,13 +1126,13 @@ xinit(int cols, int rows)
cursor = XCreateFontCursor(xw.dpy, mouseshape); cursor = XCreateFontCursor(xw.dpy, mouseshape);
XDefineCursor(xw.dpy, xw.win, cursor); XDefineCursor(xw.dpy, xw.win, cursor);
if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) { if (XParseColor(xw.dpy, xw.cmap, getcolorname(mousefg), &xmousefg) == 0) {
xmousefg.red = 0xffff; xmousefg.red = 0xffff;
xmousefg.green = 0xffff; xmousefg.green = 0xffff;
xmousefg.blue = 0xffff; xmousefg.blue = 0xffff;
} }
if (XParseColor(xw.dpy, xw.cmap, colorname[mousebg], &xmousebg) == 0) { if (XParseColor(xw.dpy, xw.cmap, getcolorname(mousebg), &xmousebg) == 0) {
xmousebg.red = 0x0000; xmousebg.red = 0x0000;
xmousebg.green = 0x0000; xmousebg.green = 0x0000;
xmousebg.blue = 0x0000; xmousebg.blue = 0x0000;