Add gruvbox both themes

This commit is contained in:
Sergey Silaev 2022-11-19 01:56:06 +04:00
parent 92e27fef1c
commit 956ac898e2
5 changed files with 149 additions and 62 deletions

View file

@ -1,6 +1,6 @@
# st - simple terminal emulator for X # st - simple terminal emulator for X
This is the terminal that I use every day, and maybe it will work for you too. This is a terminal that I use everyday, and maybe it will work for you too.
+ Based on [st-0.9](https://st.suckless.org/) with patches from 0.8.5 + Based on [st-0.9](https://st.suckless.org/) with patches from 0.8.5
+ Default theme: [gruvbox](https://github.com/morhetz/gruvbox) + Default theme: [gruvbox](https://github.com/morhetz/gruvbox)
@ -9,6 +9,7 @@ This is the terminal that I use every day, and maybe it will work for you too.
## Bindings ## Bindings
+ **Swap theme (dark|light)** : with `F11`
+ **Scrollback**: with `shift-↑/↓` + **Scrollback**: with `shift-↑/↓`
+ **Scrollback mouse**: `shift` while scrolling the mouse + **Scrollback mouse**: `shift` while scrolling the mouse
+ **Change font size**:`ctrl+shift-↑/↓` + **Change font size**:`ctrl+shift-↑/↓`

View file

@ -5,7 +5,13 @@
* *
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/ */
static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true"; static char *font = "FantasqueSansMono:pixelsize=18:antialias=true:autohint=true";
/* Spare fonts */
static char *font2[] = {
"Source Code Pro:pixelsize=16:antialias=true:autohint=true",
};
static int borderpx = 2; static int borderpx = 2;
/* /*
@ -16,7 +22,7 @@ static int borderpx = 2;
* 4: value of shell in /etc/passwd * 4: value of shell in /etc/passwd
* 5: value of shell in config.h * 5: value of shell in config.h
*/ */
static char *shell = "/bin/sh"; static char *shell = "/bin/zsh";
char *utmp = NULL; char *utmp = NULL;
/* scroll program: to enable use a string like "scroll" */ /* scroll program: to enable use a string like "scroll" */
char *scroll = NULL; char *scroll = NULL;
@ -93,29 +99,51 @@ char *termname = "st-256color";
*/ */
unsigned int tabspaces = 8; unsigned int tabspaces = 8;
/* bg opacity */
float alpha = 0.8;
/* Apprentice colorscheme */
/* 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 */ /* gruvbox dark */
[0] = "#fbf1c7", /* hard contrast: #f9f5d7 / soft contrast: #f2e5bc */ "#32302f", /* hard contrast: #1d2021 / soft contrast: #32302f */
[1] = "#cc241d", /* red */ "#cc241d", /* red */
[2] = "#98971a", /* green */ "#98971a", /* green */
[3] = "#d79921", /* yellow */ "#d79921", /* yellow */
[4] = "#458588", /* blue */ "#458588", /* blue */
[5] = "#b16286", /* magenta */ "#b16286", /* magenta */
[6] = "#689d6a", /* cyan */ "#689d6a", /* cyan */
[7] = "#7c6f64", /* white */ "#a89984", /* white */
"#928374", /* black */
/* 8 bright colors */ "#fb4934", /* red */
[8] = "#928374", /* black */ "#b8bb26", /* green */
[9] = "#9d0006", /* red */ "#fabd2f", /* yellow */
[10] = "#79740e", /* green */ "#83a598", /* blue */
[11] = "#b57614", /* yellow */ "#d3869b", /* magenta */
[12] = "#076678", /* blue */ "#8ec07c", /* cyan */
[13] = "#8f3f71", /* magenta */ "#ebdbb2", /* white */
[14] = "#427b58", /* cyan */
[15] = "#3c3836", /* white */
}; };
/* Terminal colors for alternate (light) palette */
static const char *altcolorname[] = {
/* gruvbox light */
"#fbf1c7", /* hard contrast: #f9f5d7 / soft contrast: #f2e5bc */
"#cc241d", /* red */
"#98971a", /* green */
"#d79921", /* yellow */
"#458588", /* blue */
"#b16286", /* magenta */
"#689d6a", /* cyan */
"#7c6f64", /* white */
"#928374", /* black */
"#9d0006", /* red */
"#79740e", /* green */
"#b57614", /* yellow */
"#076678", /* blue */
"#8f3f71", /* magenta */
"#427b58", /* cyan */
"#3c3836", /* white */
};
/* /*
* Default colors (colorname index) * Default colors (colorname index)
@ -126,6 +154,14 @@ unsigned int defaultbg = 0;
unsigned int defaultcs = 15; unsigned int defaultcs = 15;
static unsigned int defaultrcs = 257; static unsigned int defaultrcs = 257;
/*
* Colors used, when the specific fg == defaultfg. So in reverse mode this
* will reverse too. Another logic would only make the simple feature too
* complex.
*/
static unsigned int defaultitalic = 7;
static unsigned int defaultunderline = 7;
/* /*
* Default shape of cursor * Default shape of cursor
* 2: Block ("") * 2: Block ("")
@ -138,9 +174,8 @@ static unsigned int cursorshape = 2;
/* /*
* Default columns and rows numbers * Default columns and rows numbers
*/ */
static unsigned int cols = 110;
static unsigned int cols = 80; static unsigned int rows = 30;
static unsigned int rows = 24;
/* /*
* Default colour and shape of the mouse cursor * Default colour and shape of the mouse cursor
@ -162,37 +197,52 @@ static unsigned int defaultattr = 11;
*/ */
static uint forcemousemod = ShiftMask; static uint forcemousemod = ShiftMask;
static char *openurlcmd[] = { "/bin/sh", "-c",
"xurls | rofi -dmenu -l 10 -columns 1 | xargs -r xdg-open",
"externalpipe", NULL };
/* /*
* Internal mouse shortcuts. * Internal mouse shortcuts.
* Beware that overloading Button1 will disable the selection. * Beware that overloading Button1 will disable the selection.
*/ */
static MouseShortcut mshortcuts[] = { static MouseShortcut mshortcuts[] = {
/* mask button function argument release */ /* button mask function release */
{ XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 }, { Button4, XK_NO_MOD, ttysend, {.s = "\031"} },
{ ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} }, { Button5, XK_NO_MOD, ttysend, {.s = "\005"} },
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, { Button4, ShiftMask, ttysend, {.s = "\033[5;2~"} },
{ ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} }, { Button5, ShiftMask, ttysend, {.s = "\033[6;2~"} },
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
}; };
/* Internal keyboard shortcuts. */ /* Internal keyboard shortcuts. */
#define MODKEY Mod1Mask #define MODKEY Mod1Mask
#define TERMMOD (ControlMask|ShiftMask) #define TERMMOD (ControlMask|ShiftMask)
MouseKey mkeys[] = {
/* button mask function argument */
{ Button4, ShiftMask, kscrollup, {.i = 1} },
{ Button5, ShiftMask, kscrolldown, {.i = 1} },
{ Button4, TERMMOD, zoom, {.f = +1} },
{ Button5, TERMMOD, zoom, {.f = -1} },
};
static Shortcut shortcuts[] = { static Shortcut shortcuts[] = {
/* mask keysym function argument */ /* mask keysym function argument */
{ XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} }, { XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} },
{ ControlMask, XK_Print, toggleprinter, {.i = 0} }, { ControlMask, XK_Print, toggleprinter, {.i = 0} },
{ ShiftMask, XK_Print, printscreen, {.i = 0} }, { ShiftMask, XK_Print, printscreen, {.i = 0} },
{ XK_ANY_MOD, XK_Print, printsel, {.i = 0} }, { XK_ANY_MOD, XK_Print, printsel, {.i = 0} },
{ TERMMOD, XK_Prior, zoom, {.f = +1} }, { TERMMOD, XK_Up, zoom, {.f = +1} },
{ TERMMOD, XK_Next, zoom, {.f = -1} }, { TERMMOD, XK_Down, zoom, {.f = -1} },
{ TERMMOD, XK_Home, zoomreset, {.f = 0} }, { TERMMOD, XK_Home, zoomreset, {.f = 0} },
{ TERMMOD, XK_C, clipcopy, {.i = 0} }, { TERMMOD, XK_C, clipcopy, {.i = 0} },
{ TERMMOD, XK_V, clippaste, {.i = 0} }, { TERMMOD, XK_V, clippaste, {.i = 0} },
{ TERMMOD, XK_Y, selpaste, {.i = 0} }, { TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} }, { TERMMOD, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ TERMMOD, XK_U, externalpipe, { .v = openurlcmd } },
{ ShiftMask, XK_Up, kscrollup, {.i = -1} },
{ ShiftMask, XK_Down, kscrolldown, {.i = -1} },
{ XK_ANY_MOD, XK_F11, swapcolors, {.i = 0} },
}; };
/* /*
@ -461,6 +511,6 @@ static uint selmasks[] = {
* of single wide characters. * of single wide characters.
*/ */
static char ascii_printable[] = static char ascii_printable[] =
" !\"#$%&'()*+,-./0123456789:;<=>?" " !\"#$%&'()*+,-./0123456789:;<=>?"
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
"`abcdefghijklmnopqrstuvwxyz{|}~"; "`abcdefghijklmnopqrstuvwxyz{|}~";

View file

@ -97,7 +97,7 @@ char *termname = "st-256color";
* *
* stty tabs * stty tabs
*/ */
unsigned int tabspaces = 4; unsigned int tabspaces = 8;
/* bg opacity */ /* bg opacity */
float alpha = 0.8; float alpha = 0.8;
@ -105,26 +105,44 @@ float alpha = 0.8;
/* Apprentice colorscheme */ /* Apprentice colorscheme */
/* Terminal colors (16 first used in escape sequence) */ /* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = { static const char *colorname[] = {
/* gruvbox dark */
"#32302f", /* hard contrast: #1d2021 / soft contrast: #32302f */
"#cc241d", /* red */
"#98971a", /* green */
"#d79921", /* yellow */
"#458588", /* blue */
"#b16286", /* magenta */
"#689d6a", /* cyan */
"#a89984", /* white */
"#928374", /* black */
"#fb4934", /* red */
"#b8bb26", /* green */
"#fabd2f", /* yellow */
"#83a598", /* blue */
"#d3869b", /* magenta */
"#8ec07c", /* cyan */
"#ebdbb2", /* white */
};
/* 8 normal colors */ /* Terminal colors for alternate (light) palette */
[0] = "#32302f", /* hard contrast: #1d2021 / soft contrast: #32302f */ static const char *altcolorname[] = {
[1] = "#cc241d", /* red */ /* gruvbox light */
[2] = "#98971a", /* green */ "#fbf1c7", /* hard contrast: #f9f5d7 / soft contrast: #f2e5bc */
[3] = "#d79921", /* yellow */ "#cc241d", /* red */
[4] = "#458588", /* blue */ "#98971a", /* green */
[5] = "#b16286", /* magenta */ "#d79921", /* yellow */
[6] = "#689d6a", /* cyan */ "#458588", /* blue */
[7] = "#a89984", /* white */ "#b16286", /* magenta */
"#689d6a", /* cyan */
/* 8 bright colors */ "#7c6f64", /* white */
[8] = "#928374", /* black */ "#928374", /* black */
[9] = "#fb4934", /* red */ "#9d0006", /* red */
[10] = "#b8bb26", /* green */ "#79740e", /* green */
[11] = "#fabd2f", /* yellow */ "#b57614", /* yellow */
[12] = "#83a598", /* blue */ "#076678", /* blue */
[13] = "#d3869b", /* magenta */ "#8f3f71", /* magenta */
[14] = "#8ec07c", /* cyan */ "#427b58", /* cyan */
[15] = "#ebdbb2", /* white */ "#3c3836", /* white */
}; };
/* /*
@ -224,6 +242,7 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_U, externalpipe, { .v = openurlcmd } }, { TERMMOD, XK_U, externalpipe, { .v = openurlcmd } },
{ ShiftMask, XK_Up, kscrollup, {.i = -1} }, { ShiftMask, XK_Up, kscrollup, {.i = -1} },
{ ShiftMask, XK_Down, kscrolldown, {.i = -1} }, { ShiftMask, XK_Down, kscrolldown, {.i = -1} },
{ XK_ANY_MOD, XK_F11, swapcolors, {.i = 0} },
}; };
/* /*

1
st.h
View file

@ -130,6 +130,7 @@ extern wchar_t *worddelimiters;
extern int allowaltscreen; extern int allowaltscreen;
extern int allowwindowops; extern int allowwindowops;
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;

26
x.c
View file

@ -55,6 +55,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 *);
@ -258,6 +259,8 @@ static char *opt_title = NULL;
static uint buttons; /* bit field of pressed buttons */ static uint buttons; /* bit field of pressed buttons */
int usealtcolors = 0; /* 1 to use alternate palette */
void void
clipcopy(const Arg *dummy) clipcopy(const Arg *dummy)
{ {
@ -296,6 +299,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)
{ {
@ -783,6 +794,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)
{ {
@ -801,7 +817,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);
@ -824,8 +840,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);
} }
@ -1332,13 +1348,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;