Compare commits
7 Commits
patched-3
...
38750d3bf4
| Author | SHA1 | Date | |
|---|---|---|---|
| 38750d3bf4 | |||
|
|
4faf074fb7 | ||
| b406d11a74 | |||
| b92efccbab | |||
| 57940e9403 | |||
| 6ba0170dd6 | |||
|
|
04ea60ca8e |
115
config.def.h
115
config.def.h
@@ -93,46 +93,87 @@ char *termname = "st-256color";
|
||||
*/
|
||||
unsigned int tabspaces = 8;
|
||||
|
||||
/* Terminal colors (16 first used in escape sequence) */
|
||||
static const char *colorname[] = {
|
||||
/* 8 normal colors */
|
||||
"black",
|
||||
"red3",
|
||||
"green3",
|
||||
"yellow3",
|
||||
"blue2",
|
||||
"magenta3",
|
||||
"cyan3",
|
||||
"gray90",
|
||||
typedef struct {
|
||||
const char* const colors[258]; /* terminal colors */
|
||||
unsigned int fg; /* foreground */
|
||||
unsigned int bg; /* background */
|
||||
unsigned int cs; /* cursor */
|
||||
unsigned int rcs; /* reverse cursor */
|
||||
} ColorScheme;
|
||||
/*
|
||||
* Terminal colors (16 first used in escape sequence,
|
||||
* 2 last for custom cursor color),
|
||||
* foreground, background, cursor, reverse cursor
|
||||
*/
|
||||
static const ColorScheme schemes[] = {
|
||||
// st (dark)
|
||||
{{"black", "red3", "green3", "yellow3",
|
||||
"blue2", "magenta3", "cyan3", "gray90",
|
||||
"gray50", "red", "green", "yellow",
|
||||
"#5c5cff", "magenta", "cyan", "white",
|
||||
[256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
||||
|
||||
/* 8 bright colors */
|
||||
"gray50",
|
||||
"red",
|
||||
"green",
|
||||
"yellow",
|
||||
"#5c5cff",
|
||||
"magenta",
|
||||
"cyan",
|
||||
"white",
|
||||
// Alacritty (dark)
|
||||
{{"#1d1f21", "#cc6666", "#b5bd68", "#f0c674",
|
||||
"#81a2be", "#b294bb", "#8abeb7", "#c5c8c6",
|
||||
"#666666", "#d54e53", "#b9ca4a", "#e7c547",
|
||||
"#7aa6da", "#c397d8", "#70c0b1", "#eaeaea",
|
||||
[256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
||||
|
||||
[255] = 0,
|
||||
// One Half dark
|
||||
{{"#282c34", "#e06c75", "#98c379", "#e5c07b",
|
||||
"#61afef", "#c678dd", "#56b6c2", "#dcdfe4",
|
||||
"#282c34", "#e06c75", "#98c379", "#e5c07b",
|
||||
"#61afef", "#c678dd", "#56b6c2", "#dcdfe4",
|
||||
[256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
||||
|
||||
/* more colors can be added after 255 to use with DefaultXX */
|
||||
"#cccccc",
|
||||
"#555555",
|
||||
"gray90", /* default foreground colour */
|
||||
"black", /* default background colour */
|
||||
// One Half light
|
||||
{{"#fafafa", "#e45649", "#50a14f", "#c18401",
|
||||
"#0184bc", "#a626a4", "#0997b3", "#383a42",
|
||||
"#fafafa", "#e45649", "#50a14f", "#c18401",
|
||||
"#0184bc", "#a626a4", "#0997b3", "#383a42",
|
||||
[256]="#cccccc", "#555555"}, 7, 0, 256, 257},
|
||||
|
||||
// Lupan dark
|
||||
{{"#1f212e", "#862d2d", "#3a783a", "#707010",
|
||||
"#345eb2", "#cc66cc", "#3a7878", "#a1a3aa",
|
||||
"#4d4d4d", "#c27070", "#40bf40", "#acac53",
|
||||
"#6b8ac7", "#8f248f", "#509595", "#dbdff0",
|
||||
[256]="#bf8040", "#555555"}, 7, 0, 256, 257},
|
||||
|
||||
// Lupan light
|
||||
{{"#1f212e", "#862d2d", "#3a783a", "#707010",
|
||||
"#345eb2", "#cc66cc", "#3a7878", "#a1a3aa",
|
||||
"#73778c", "#c27070", "#40bf40", "#acac53",
|
||||
"#6b8ac7", "#8f248f", "#509595", "#dbdff0",
|
||||
[256]="#bf8040", "#555555"}, 0, 15, 256, 257},
|
||||
|
||||
// Gruvbox dark
|
||||
{{"#282828", "#cc241d", "#98971a", "#d79921",
|
||||
"#458588", "#b16286", "#689d6a", "#a89984",
|
||||
"#928374", "#fb4934", "#b8bb26", "#fabd2f",
|
||||
"#83a598", "#d3869b", "#8ec07c", "#ebdbb2",
|
||||
[256]="#ebdbb2", "#555555"}, 15, 0, 256, 257},
|
||||
|
||||
// Gruvbox light
|
||||
{{"#fbf1c7", "#cc241d", "#98971a", "#d79921",
|
||||
"#458588", "#b16286", "#689d6a", "#7c6f64",
|
||||
"#928374", "#9d0006", "#79740e", "#b57614",
|
||||
"#076678", "#8f3f71", "#427b58", "#3c3836",
|
||||
[256]="#3c3836", "#555555"}, 15, 0, 256, 257},
|
||||
};
|
||||
|
||||
static const char * const * colorname;
|
||||
int colorscheme = 0;
|
||||
|
||||
/*
|
||||
* Default colors (colorname index)
|
||||
* foreground, background, cursor, reverse cursor
|
||||
*/
|
||||
unsigned int defaultfg = 258;
|
||||
unsigned int defaultbg = 259;
|
||||
unsigned int defaultcs = 256;
|
||||
static unsigned int defaultrcs = 257;
|
||||
unsigned int defaultfg;
|
||||
unsigned int defaultbg;
|
||||
unsigned int defaultcs;
|
||||
static unsigned int defaultrcs;
|
||||
|
||||
/*
|
||||
* Default shape of cursor
|
||||
@@ -205,6 +246,18 @@ static Shortcut shortcuts[] = {
|
||||
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
||||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
||||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
||||
{ MODKEY|ControlMask, XK_1, selectscheme, {.i = 0} },
|
||||
{ MODKEY|ControlMask, XK_2, selectscheme, {.i = 1} },
|
||||
{ MODKEY|ControlMask, XK_3, selectscheme, {.i = 2} },
|
||||
{ MODKEY|ControlMask, XK_4, selectscheme, {.i = 3} },
|
||||
{ MODKEY|ControlMask, XK_5, selectscheme, {.i = 4} },
|
||||
{ MODKEY|ControlMask, XK_6, selectscheme, {.i = 5} },
|
||||
{ MODKEY|ControlMask, XK_7, selectscheme, {.i = 6} },
|
||||
{ MODKEY|ControlMask, XK_8, selectscheme, {.i = 7} },
|
||||
{ MODKEY|ControlMask, XK_9, nextscheme, {.i = -1} },
|
||||
{ MODKEY|ControlMask, XK_0, nextscheme, {.i = +1} },
|
||||
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
|
||||
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
|
||||
{ ACMPL_MOD, XK_slash, autocomplete, { .i = ACMPL_WORD } },
|
||||
{ ACMPL_MOD, XK_period, autocomplete, { .i = ACMPL_FUZZY_WORD } },
|
||||
{ ACMPL_MOD, XK_comma, autocomplete, { .i = ACMPL_FUZZY } },
|
||||
@@ -213,8 +266,6 @@ static Shortcut shortcuts[] = {
|
||||
{ ACMPL_MOD, XK_bracketright,autocomplete, { .i = ACMPL_WWORD } },
|
||||
{ ACMPL_MOD, XK_bracketleft, autocomplete, { .i = ACMPL_FUZZY_WWORD } },
|
||||
{ ACMPL_MOD, XK_equal, autocomplete, { .i = ACMPL_UNDO } },
|
||||
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
|
||||
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
22
st.c
22
st.c
@@ -2292,6 +2292,28 @@ tstrsequence(uchar c)
|
||||
term.esc |= ESC_STR;
|
||||
}
|
||||
|
||||
void
|
||||
tupdatebgcolor(int oldbg, int newbg)
|
||||
{
|
||||
for (int y = 0; y < term.row; y++) {
|
||||
for (int x = 0; x < term.col; x++) {
|
||||
if (TLINE(y)[x].bg == oldbg)
|
||||
TLINE(y)[x].bg = newbg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tupdatefgcolor(int oldfg, int newfg)
|
||||
{
|
||||
for (int y = 0; y < term.row; y++) {
|
||||
for (int x = 0; x < term.col; x++) {
|
||||
if (TLINE(y)[x].fg == oldfg)
|
||||
TLINE(y)[x].fg = newfg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tcontrolcode(uchar ascii)
|
||||
{
|
||||
|
||||
2
st.h
2
st.h
@@ -93,6 +93,8 @@ int tattrset(int);
|
||||
void tnew(int, int);
|
||||
void tresize(int, int);
|
||||
void tsetdirtattr(int);
|
||||
void tupdatebgcolor(int, int);
|
||||
void tupdatefgcolor(int, int);
|
||||
void ttyhangup(void);
|
||||
int ttynew(const char *, char *, const char *, char **);
|
||||
size_t ttyread(void);
|
||||
|
||||
167
x.c
167
x.c
@@ -14,7 +14,6 @@
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <X11/XKBlib.h>
|
||||
#include <X11/Xresource.h>
|
||||
|
||||
char *argv0;
|
||||
#include "arg.h"
|
||||
@@ -60,6 +59,8 @@ static void zoom(const Arg *);
|
||||
static void zoomabs(const Arg *);
|
||||
static void zoomreset(const Arg *);
|
||||
static void ttysend(const Arg *);
|
||||
static void nextscheme(const Arg *);
|
||||
static void selectscheme(const Arg *);
|
||||
void kscrollup(const Arg *);
|
||||
void kscrolldown(const Arg *);
|
||||
|
||||
@@ -188,6 +189,7 @@ static void mousesel(XEvent *, int);
|
||||
static void mousereport(XEvent *);
|
||||
static char *kmap(KeySym, uint);
|
||||
static int match(uint, uint);
|
||||
static void updatescheme(void);
|
||||
|
||||
static void run(void);
|
||||
static void usage(void);
|
||||
@@ -804,7 +806,7 @@ xloadcols(void)
|
||||
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
|
||||
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
|
||||
} else {
|
||||
dc.collen = MAX(LEN(colorname), 256);
|
||||
dc.collen = 258;
|
||||
dc.col = xmalloc(dc.collen * sizeof(Color));
|
||||
}
|
||||
|
||||
@@ -2035,118 +2037,6 @@ run(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define XRESOURCE_LOAD_META(NAME) \
|
||||
if(!XrmGetResource(xrdb, "st." NAME, "st." NAME, &type, &ret)) \
|
||||
XrmGetResource(xrdb, "*." NAME, "*." NAME, &type, &ret); \
|
||||
if (ret.addr != NULL && !strncmp("String", type, 64))
|
||||
|
||||
#define XRESOURCE_LOAD_STRING(NAME, DST) \
|
||||
XRESOURCE_LOAD_META(NAME) \
|
||||
DST = ret.addr;
|
||||
|
||||
#define XRESOURCE_LOAD_CHAR(NAME, DST) \
|
||||
XRESOURCE_LOAD_META(NAME) \
|
||||
DST = ret.addr[0];
|
||||
|
||||
#define XRESOURCE_LOAD_INTEGER(NAME, DST) \
|
||||
XRESOURCE_LOAD_META(NAME) \
|
||||
DST = strtoul(ret.addr, NULL, 10);
|
||||
|
||||
#define XRESOURCE_LOAD_FLOAT(NAME, DST) \
|
||||
XRESOURCE_LOAD_META(NAME) \
|
||||
DST = strtof(ret.addr, NULL);
|
||||
|
||||
void
|
||||
xrdb_load(void)
|
||||
{
|
||||
/* XXX */
|
||||
char *xrm;
|
||||
char *type;
|
||||
XrmDatabase xrdb;
|
||||
XrmValue ret;
|
||||
Display *dpy;
|
||||
|
||||
if(!(dpy = XOpenDisplay(NULL)))
|
||||
die("Can't open display\n");
|
||||
|
||||
XrmInitialize();
|
||||
xrm = XResourceManagerString(dpy);
|
||||
|
||||
if (xrm != NULL) {
|
||||
xrdb = XrmGetStringDatabase(xrm);
|
||||
|
||||
/* handling colors here without macros to do via loop. */
|
||||
int i = 0;
|
||||
char loadValue[12] = "";
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
sprintf(loadValue, "%s%d", "st.color", i);
|
||||
|
||||
if(!XrmGetResource(xrdb, loadValue, loadValue, &type, &ret))
|
||||
{
|
||||
sprintf(loadValue, "%s%d", "*.color", i);
|
||||
if (!XrmGetResource(xrdb, loadValue, loadValue, &type, &ret))
|
||||
/* reset if not found (unless in range for defaults). */
|
||||
if (i > 15)
|
||||
colorname[i] = NULL;
|
||||
}
|
||||
|
||||
if (ret.addr != NULL && !strncmp("String", type, 64))
|
||||
colorname[i] = ret.addr;
|
||||
}
|
||||
|
||||
XRESOURCE_LOAD_STRING("foreground", colorname[defaultfg]);
|
||||
XRESOURCE_LOAD_STRING("background", colorname[defaultbg]);
|
||||
XRESOURCE_LOAD_STRING("cursorColor", colorname[defaultcs])
|
||||
else {
|
||||
// this looks confusing because we are chaining off of the if
|
||||
// in the macro. probably we should be wrapping everything blocks
|
||||
// so this isn't possible...
|
||||
defaultcs = defaultfg;
|
||||
}
|
||||
XRESOURCE_LOAD_STRING("reverse-cursor", colorname[defaultrcs])
|
||||
else {
|
||||
// see above.
|
||||
defaultrcs = defaultbg;
|
||||
}
|
||||
|
||||
XRESOURCE_LOAD_STRING("font", font);
|
||||
XRESOURCE_LOAD_STRING("termname", termname);
|
||||
|
||||
XRESOURCE_LOAD_INTEGER("blinktimeout", blinktimeout);
|
||||
XRESOURCE_LOAD_INTEGER("bellvolume", bellvolume);
|
||||
XRESOURCE_LOAD_INTEGER("borderpx", borderpx);
|
||||
XRESOURCE_LOAD_INTEGER("cursorshape", cursorshape);
|
||||
|
||||
XRESOURCE_LOAD_FLOAT("cwscale", cwscale);
|
||||
XRESOURCE_LOAD_FLOAT("chscale", chscale);
|
||||
}
|
||||
XFlush(dpy);
|
||||
}
|
||||
|
||||
void
|
||||
reload(int sig)
|
||||
{
|
||||
xrdb_load();
|
||||
|
||||
/* colors, fonts */
|
||||
xloadcols();
|
||||
xunloadfonts();
|
||||
xloadfonts(font, 0);
|
||||
|
||||
/* pretend the window just got resized */
|
||||
cresize(win.w, win.h);
|
||||
|
||||
redraw();
|
||||
|
||||
/* triggers re-render if we're visible. */
|
||||
ttywrite("\033[O", 3, 1);
|
||||
|
||||
signal(SIGUSR1, reload);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
@@ -2160,6 +2050,47 @@ usage(void)
|
||||
" [stty_args ...]\n", argv0, argv0);
|
||||
}
|
||||
|
||||
void
|
||||
nextscheme(const Arg *arg)
|
||||
{
|
||||
colorscheme += arg->i;
|
||||
if (colorscheme >= (int)LEN(schemes))
|
||||
colorscheme = 0;
|
||||
else if (colorscheme < 0)
|
||||
colorscheme = LEN(schemes) - 1;
|
||||
updatescheme();
|
||||
}
|
||||
|
||||
void
|
||||
selectscheme(const Arg *arg)
|
||||
{
|
||||
if (BETWEEN(arg->i, 0, LEN(schemes)-1)) {
|
||||
colorscheme = arg->i;
|
||||
updatescheme();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
updatescheme(void)
|
||||
{
|
||||
int oldbg, oldfg;
|
||||
|
||||
oldbg = defaultbg;
|
||||
oldfg = defaultfg;
|
||||
colorname = schemes[colorscheme].colors;
|
||||
defaultbg = schemes[colorscheme].bg;
|
||||
defaultfg = schemes[colorscheme].fg;
|
||||
defaultcs = schemes[colorscheme].cs;
|
||||
defaultrcs = schemes[colorscheme].rcs;
|
||||
xloadcols();
|
||||
if (defaultbg != oldbg)
|
||||
tupdatebgcolor(oldbg, defaultbg);
|
||||
if (defaultfg != oldfg)
|
||||
tupdatefgcolor(oldfg, defaultfg);
|
||||
cresize(win.w, win.h);
|
||||
redraw();
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
@@ -2212,6 +2143,12 @@ main(int argc, char *argv[])
|
||||
} ARGEND;
|
||||
|
||||
run:
|
||||
colorname = schemes[colorscheme].colors;
|
||||
defaultbg = schemes[colorscheme].bg;
|
||||
defaultfg = schemes[colorscheme].fg;
|
||||
defaultcs = schemes[colorscheme].cs;
|
||||
defaultrcs = schemes[colorscheme].rcs;
|
||||
|
||||
if (argc > 0) /* eat all remaining arguments */
|
||||
opt_cmd = argv;
|
||||
|
||||
@@ -2220,8 +2157,6 @@ run:
|
||||
|
||||
setlocale(LC_CTYPE, "");
|
||||
XSetLocaleModifiers("");
|
||||
xrdb_load();
|
||||
signal(SIGUSR1, reload);
|
||||
cols = MAX(cols, 1);
|
||||
rows = MAX(rows, 1);
|
||||
tnew(cols, rows);
|
||||
|
||||
Reference in New Issue
Block a user