10 Commits

Author SHA1 Message Date
5d6d2c98c7 st-meta-vim-full: change currentBg, introduce currentFg 2026-01-22 09:19:59 +01:00
Justinas Grigas
02739346a8 cyclefonts: keybind to cycle fonts (agree with st-xresources-signal-reloading)
This patch is an update to the 20210604, which fixes zoomreset.

Because the cyclefonts function doesn't change the defaultfontsize
variable, zoomreset function resets all fonts to the size of the first
one loaded.

With this patch, zoomreset will reset the font to the specified fontsize
2026-01-22 08:22:36 +01:00
wael
f37ea1f018 update to 0.8.5 (apply patch st-csi_22_23-0.8.5.diff) 2026-01-22 08:02:55 +01:00
01873515e4 agree st-clickurl with st-externalpipe 2026-01-22 07:53:25 +01:00
Jishnu Sen
c639b09920 Highlight URLs with control and follow with click 2026-01-22 07:50:51 +01:00
3c61f404b9 apply patch st-expected-anysize-0.9.diff 2026-01-22 07:43:32 +01:00
1d15a6b4d5 add dmenu dark and light variants 2026-01-22 07:42:58 +01:00
0336421c97 add copy/paste dmenu prompt and remove empty values from completion list 2026-01-22 07:42:49 +01:00
7959aba0bf add key to insert text selected with dmenu as terminal input 2026-01-22 07:42:34 +01:00
278f7b1869 add keys to edit screen content with editor and copy WORD using externalpipe 2026-01-22 07:42:04 +01:00
7 changed files with 345 additions and 26 deletions

View File

@@ -5,9 +5,51 @@
*
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/
static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
static char *fonts[] = {
"FiraCode Nerd Font:size=10",
"Monaspace Neon:size=10",
"Monaspace Argon:size=10",
"Monaspace Xenon:size=10",
"Monaspace Radon:size=10",
"Monaspace Krypton:size=10",
};
static size_t currentfont = 0;
static int borderpx = 2;
static char *externaleditcmd[] = { "/bin/sh", "-c",
"tmpfile=$(mktemp /tmp/st-edit.XXXXXX)\n"
"trap 'rm \"$tmpfile\"' 0 1 15\n"
"cat > \"$tmpfile\"\n"
"st -e vis \"$tmpfile\"\n",
NULL};
int lightmode = 0;
#define COL_GRAY1 "'#222222'"
#define COL_GRAY2 "'#444444'"
#define COL_GRAY3 "'#bbbbbb'"
#define COL_GRAY4 "'#eeeeee'"
#define COL_CYAN "'#005577'"
#define DMENU_DARK "-l 10 -fn 'FiraCode Nerd Font:size=10' -nb " COL_GRAY1 " -nf " COL_GRAY3 " -sb " COL_CYAN " -sf " COL_GRAY4
#define DMENU_LIGHT "-l 10 -fn 'FiraCode Nerd Font:size=10' -nb " COL_GRAY3 " -nf " COL_GRAY1 " -sb " COL_CYAN " -sf " COL_GRAY4
static char *externalcopydarkcmd[] = { "/bin/sh", "-c",
"sed 's/[ \t][ \t]*/\\n/g' | tac | awk 'BEGIN{x[\"\"]++} !x[$0]++' | dmenu " DMENU_DARK " -w $WINDOWID -p Copy | tr -d '\\n' | vis-clipboard --copy",
NULL};
static char *externalpastedarkcmd[] = { "/bin/sh", "-c",
"sed 's/[ \t][ \t]*/\\n/g' | tac | awk 'BEGIN{x[\"\"]++} !x[$0]++' | dmenu " DMENU_DARK " -w $WINDOWID -p Paste | tr -d '\\n'",
NULL};
static char *externalcopylightcmd[] = { "/bin/sh", "-c",
"sed 's/[ \t][ \t]*/\\n/g' | tac | awk 'BEGIN{x[\"\"]++} !x[$0]++' | dmenu " DMENU_LIGHT " -w $WINDOWID -p Copy | tr -d '\\n' | vis-clipboard --copy",
NULL};
static char *externalpastelightcmd[] = { "/bin/sh", "-c",
"sed 's/[ \t][ \t]*/\\n/g' | tac | awk 'BEGIN{x[\"\"]++} !x[$0]++' | dmenu " DMENU_LIGHT " -w $WINDOWID -p Paste | tr -d '\\n'",
NULL};
/*
* What program is execed by st depends of these precedence rules:
* 1: program passed with -e
@@ -133,7 +175,7 @@ unsigned int defaultfg = 258;
unsigned int defaultbg = 259;
unsigned int defaultcs = 256;
static unsigned int defaultrcs = 257;
unsigned int const currentBg = 6, buffSize = 2048;
unsigned int const currentBg = 179, currentFg = 0, buffSize = 2048;
/// Enable double / triple click yanking / selection of word / line.
int const mouseYank = 1, mouseSelect = 0;
/// [Vim Browse] Colors for search results currently on screen.
@@ -214,9 +256,13 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_C, clipcopy, {.i = 0} },
{ TERMMOD, XK_V, clippaste, {.i = 0} },
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
{ TERMMOD, XK_E, externalpipe, { .v = externaleditcmd } },
{ TERMMOD, XK_K, externalpipecopy, { 0 } },
{ TERMMOD, XK_I, externalpipepaste, { 0 } },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ MODKEY, XK_c, normalMode, {.i = 0} },
{ TERMMOD, XK_S, cyclefonts, {} },
};
/*
@@ -488,3 +534,14 @@ static char ascii_printable[] =
" !\"#$%&'()*+,-./0123456789:;<=>?"
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
"`abcdefghijklmnopqrstuvwxyz{|}~";
/*
* Open urls starting with urlprefixes, contatining urlchars
* by passing as ARG1 to urlhandler.
*/
char* urlhandler = "xdg-open";
char urlchars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789-._~:/?#@!$&'*+,;=%";
char* urlprefixes[] = {"http://", "https://", NULL};

View File

@@ -6,7 +6,7 @@
extern Glyph const styleSearch, style[];
extern char const wDelS[], wDelL[], *nmKeys[];
extern unsigned int bg[], fg, currentBg, highlightBg, highlightFg, amountNmKeys;
extern unsigned int bg[], fg, currentBg, currentFg, highlightBg, highlightFg, amountNmKeys;
typedef struct { int p[3]; } Pos;
@@ -264,7 +264,7 @@ void historyOverlay(int x, int y, Glyph* g) {
else if (x > term.col - 7) g->u = (Rune)(posBuffer[x - term.col + 7]);
else getChar(size(&cCmd) ?&cCmd :&lCmd, g, term.row-1, term.col-7, term.col/3-6, x);
} else if (highlighted(x, y)) g->bg = highlightBg, g->fg = highlightFg;
else if ((x==cHist->x) ^ (y==cHist->y)) g->bg = currentBg;
else if ((x==cHist->x) ^ (y==cHist->y)) { g->bg = currentBg; g->fg = currentFg; }
else if (x==cHist->x) g->mode^=ATTR_REVERSE;
}
void historyPreDraw() {

183
st.c
View File

@@ -643,6 +643,97 @@ getsel(void)
return str;
}
char *
strstrany(char* s, char** strs) {
char *match;
for (int i = 0; strs[i]; i++) {
if ((match = strstr(s, strs[i]))) {
return match;
}
}
return NULL;
}
void
highlighturls(void)
{
char *match;
char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */
for (int i = term.top; i < term.bot; i++) {
int url_start = -1;
for (int j = 0; j < term.col; j++) {
if (term.line[i][j].u < 127) {
linestr[j] = term.line[i][j].u;
}
linestr[term.col] = '\0';
}
while ((match = strstrany(linestr + url_start + 1, urlprefixes))) {
url_start = match - linestr;
for (int c = url_start; c < term.col && strchr(urlchars, linestr[c]); c++) {
term.line[i][c].mode |= ATTR_URL;
tsetdirt(i, c);
}
}
}
free(linestr);
}
void
unhighlighturls(void)
{
for (int i = term.top; i < term.bot; i++) {
for (int j = 0; j < term.col; j++) {
Glyph* g = &term.line[i][j];
if (g->mode & ATTR_URL) {
g->mode &= ~ATTR_URL;
tsetdirt(i, j);
}
}
}
return;
}
void
followurl(int x, int y) {
char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */
char *match;
for (int i = 0; i < term.col; i++) {
if (term.line[x][i].u < 127) {
linestr[i] = term.line[x][i].u;
}
linestr[term.col] = '\0';
}
int url_start = -1;
while ((match = strstrany(linestr + url_start + 1, urlprefixes))) {
url_start = match - linestr;
int url_end = url_start;
for (int c = url_start; c < term.col && strchr(urlchars, linestr[c]); c++) {
url_end++;
}
if (url_start <= y && y < url_end) {
linestr[url_end] = '\0';
break;
}
}
if (url_start == -1) {
free(linestr);
return;
}
pid_t chpid;
if ((chpid = fork()) == 0) {
if (fork() == 0)
execlp(urlhandler, urlhandler, linestr + url_start, NULL);
exit(1);
}
/* // handled by st-externalpipe patch
if (chpid > 0)
waitpid(chpid, NULL, 0);
*/
free(linestr);
unhighlighturls();
}
void
selclear(void)
{
@@ -1837,6 +1928,33 @@ csihandle(void)
goto unknown;
}
break;
case 't': /* title stack operations */
switch (csiescseq.arg[0]) {
case 22: /* pust current title on stack */
switch (csiescseq.arg[1]) {
case 0:
case 1:
case 2:
xpushtitle();
break;
default:
goto unknown;
}
break;
case 23: /* pop last title from stack */
switch (csiescseq.arg[1]) {
case 0:
case 1:
case 2:
xsettitle(NULL, 1);
break;
default:
goto unknown;
}
break;
default:
goto unknown;
}
}
}
@@ -1915,7 +2033,7 @@ strhandle(void)
switch (par) {
case 0:
if (narg > 1) {
xsettitle(strescseq.args[1]);
xsettitle(strescseq.args[1], 0);
xseticontitle(strescseq.args[1]);
}
return;
@@ -1925,7 +2043,7 @@ strhandle(void)
return;
case 2:
if (narg > 1)
xsettitle(strescseq.args[1]);
xsettitle(strescseq.args[1], 0);
return;
case 52: /* manipulate selection data */
if (narg > 2 && allowwindowops) {
@@ -1997,7 +2115,7 @@ strhandle(void)
}
break;
case 'k': /* old title set compatibility */
xsettitle(strescseq.args[0]);
xsettitle(strescseq.args[0], 0);
return;
case 'P': /* DCS -- Device Control String */
case '_': /* APC -- Application Program Command */
@@ -2032,9 +2150,9 @@ strparse(void)
}
void
externalpipe(const Arg *arg)
externalpipeinout(const Arg *arg, void (*processout)(int fildes))
{
int to[2];
int to[2], from[2];
char buf[UTF_SIZ];
void (*oldsigpipe)(int);
Glyph *bp, *end;
@@ -2042,16 +2160,27 @@ externalpipe(const Arg *arg)
if (pipe(to) == -1)
return;
if (processout != NULL && pipe(from) == -1)
return;
switch (fork()) {
case -1:
close(to[0]);
close(to[1]);
if (processout != NULL) {
close(from[0]);
close(from[1]);
}
return;
case 0:
dup2(to[0], STDIN_FILENO);
close(to[0]);
close(to[1]);
if (processout != NULL) {
dup2(from[1], STDOUT_FILENO);
close(from[0]);
close(from[1]);
}
execvp(((char **)arg->v)[0], (char **)arg->v);
fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
perror("failed");
@@ -2059,6 +2188,8 @@ externalpipe(const Arg *arg)
}
close(to[0]);
if (processout != NULL)
close(from[1]);
/* ignore sigpipe for now, in case child exists early */
oldsigpipe = signal(SIGPIPE, SIG_IGN);
newline = 0;
@@ -2080,10 +2211,49 @@ externalpipe(const Arg *arg)
if (newline)
(void)xwrite(to[1], "\n", 1);
close(to[1]);
if (processout != NULL) {
processout(from[0]);
close(from[0]);
}
/* restore */
signal(SIGPIPE, oldsigpipe);
}
void
externalpipe(const Arg *arg)
{
externalpipeinout(arg, NULL);
}
void
ttycopy(int fildes)
{
char buf[256];
int len;
len = read(fildes, buf, sizeof(buf));
if (len > 0 && len < sizeof(buf)) {
buf[len] = '\0';
ttywrite(buf, len, 1);
}
}
void
externalpipepaste(const Arg *)
{
Arg arg;
arg.v = externalpastecmd();
externalpipeinout(&arg, ttycopy);
}
void
externalpipecopy(const Arg *)
{
Arg arg;
arg.v = externalcopycmd();
externalpipeinout(&arg, NULL);
}
void
strdump(void)
{
@@ -2422,6 +2592,7 @@ eschandle(uchar ascii)
break;
case 'c': /* RIS -- Reset to initial state */
treset();
xfreetitlestack();
resettitle();
xloadcols();
xsetmode(0, MODE_HIDE);
@@ -2724,7 +2895,7 @@ tresize(int col, int row)
void
resettitle(void)
{
xsettitle(NULL);
xsettitle(NULL, 0);
}
void

15
st.h
View File

@@ -35,6 +35,7 @@ enum glyph_attribute {
ATTR_WIDE = 1 << 9,
ATTR_WDUMMY = 1 << 10,
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
ATTR_URL = 1 << 14,
};
enum selection_mode {
@@ -83,6 +84,8 @@ void redraw(void);
void draw(void);
void externalpipe(const Arg *);
void externalpipecopy(const Arg *);
void externalpipepaste(const Arg *);
void printscreen(const Arg *);
void printsel(const Arg *);
void sendbreak(const Arg *);
@@ -108,6 +111,10 @@ void selextend(int, int, int, int);
int selected(int, int);
char *getsel(void);
void highlighturls(void);
void unhighlighturls(void);
void followurl(int, int);
size_t utf8encode(Rune, char *);
void *xmalloc(size_t);
@@ -122,8 +129,16 @@ extern char *vtiden;
extern wchar_t *worddelimiters;
extern int allowaltscreen;
extern int allowwindowops;
extern int lightmode;
extern char *termname;
extern unsigned int tabspaces;
extern unsigned int defaultfg;
extern unsigned int defaultbg;
extern unsigned int defaultcs;
extern char *urlhandler;
extern char urlchars[];
extern char *urlprefixes[];
extern int nurlprefixes;
char **externalcopycmd();
char **externalpastecmd();

View File

@@ -161,7 +161,7 @@ st-mono| simpleterm monocolor,
rin=\E[%p1%dT,
ritm=\E[23m,
rmacs=\E(B,
rmcup=\E[?1049l,
rmcup=\E[?1049l\E[23;0;0t,
rmir=\E[4l,
rmkx=\E[?1l\E>,
rmso=\E[27m,
@@ -172,7 +172,7 @@ st-mono| simpleterm monocolor,
sitm=\E[3m,
sgr0=\E[0m,
smacs=\E(0,
smcup=\E[?1049h,
smcup=\E[?1049h\E[22;0;0t,
smir=\E[4h,
smkx=\E[?1h\E=,
smso=\E[7m,

4
win.h
View File

@@ -33,7 +33,9 @@ void xloadcols(void);
int xsetcolorname(int, const char *);
int xgetcolor(int, unsigned char *, unsigned char *, unsigned char *);
void xseticontitle(char *);
void xsettitle(char *);
void xfreetitlestack(void);
void xsettitle(char *, int);
void xpushtitle(void);
int xsetcursor(int);
void xsetmode(int, unsigned int);
void xsetpointermotion(int);

98
x.c
View File

@@ -61,10 +61,24 @@ static void zoom(const Arg *);
static void zoomabs(const Arg *);
static void zoomreset(const Arg *);
static void ttysend(const Arg *);
static void cyclefonts(const Arg *);
/* config.h for applying patches and the configuration. */
#include "config.h"
char **externalcopycmd()
{
return (lightmode) ? externalcopylightcmd : externalcopydarkcmd;
}
char **externalpastecmd()
{
return (lightmode) ? externalpastelightcmd : externalpastedarkcmd;
}
/* size of title stack */
#define TITLESTACKSIZE 8
/* XEMBED messages */
#define XEMBED_FOCUS_IN 4
#define XEMBED_FOCUS_OUT 5
@@ -193,6 +207,7 @@ static void usage(void);
static void (*handler[LASTEvent])(XEvent *) = {
[KeyPress] = kpress,
[KeyRelease] = kpress,
[ClientMessage] = cmessage,
[ConfigureNotify] = resize,
[VisibilityNotify] = visibility,
@@ -222,6 +237,8 @@ static DC dc;
static XWindow xw;
static XSelection xsel;
static TermWindow win;
static int tstki; /* title stack index */
static char *titlestack[TITLESTACKSIZE]; /* title stack */
/* Font Ring Cache */
enum {
@@ -318,11 +335,7 @@ void
zoomreset(const Arg *arg)
{
Arg larg;
if (defaultfontsize > 0) {
larg.f = defaultfontsize;
zoomabs(&larg);
}
}
void
@@ -347,6 +360,15 @@ evrow(XEvent *e)
return y / win.ch;
}
void cyclefonts(const Arg *arg) {
currentfont++;
currentfont %= (sizeof fonts / sizeof fonts[0]);
usedfont = fonts[currentfont];
Arg larg;
larg.f = usedfontsize;
zoomabs(&larg);
}
void
mousesel(XEvent *e, int done)
{
@@ -455,6 +477,15 @@ mouseaction(XEvent *e, uint release)
/* ignore Button<N>mask for Button<N> - it's set on release */
uint state = e->xbutton.state & ~buttonmask(e->xbutton.button);
if (release == 0 &&
e->xbutton.button == Button1 &&
(match(ControlMask, state) ||
match(ControlMask, state & ~forcemousemod))) {
followurl(evrow(e), evcol(e));
return 1;
}
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
if (ms->release == release &&
ms->button == e->xbutton.button &&
@@ -889,8 +920,8 @@ xhints(void)
sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize;
sizeh->height = win.h;
sizeh->width = win.w;
sizeh->height_inc = win.ch;
sizeh->width_inc = win.cw;
sizeh->height_inc = 1;
sizeh->width_inc = 1;
sizeh->base_height = 2 * borderpx;
sizeh->base_width = 2 * borderpx;
sizeh->min_height = win.ch + 2 * borderpx;
@@ -1164,7 +1195,7 @@ xinit(int cols, int rows)
if (!FcInit())
die("could not init fontconfig.\n");
usedfont = (opt_font == NULL)? font : opt_font;
usedfont = (opt_font == NULL) ? fonts[currentfont] : opt_font;
xloadfonts(usedfont, 0);
/* colors */
@@ -1517,7 +1548,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
/* Render underline and strikethrough. */
if (base.mode & ATTR_UNDERLINE) {
if (base.mode & ATTR_UNDERLINE || base.mode & ATTR_URL) {
XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent * chscale + 1,
width, 1);
}
@@ -1654,10 +1685,30 @@ xseticontitle(char *p)
}
void
xsettitle(char *p)
xfreetitlestack(void)
{
for (int i = 0; i < LEN(titlestack); i++) {
free(titlestack[i]);
titlestack[i] = NULL;
}
}
void
xsettitle(char *p, int pop)
{
XTextProperty prop;
DEFAULT(p, opt_title);
free(titlestack[tstki]);
if (pop) {
titlestack[tstki] = NULL;
tstki = (tstki - 1 + TITLESTACKSIZE) % TITLESTACKSIZE;
p = titlestack[tstki] ? titlestack[tstki] : opt_title;
} else if (p) {
titlestack[tstki] = xstrdup(p);
} else {
titlestack[tstki] = NULL;
p = opt_title;
}
if (p[0] == '\0')
p = opt_title;
@@ -1670,6 +1721,16 @@ xsettitle(char *p)
XFree(prop.value);
}
void
xpushtitle(void)
{
int tstkin = (tstki + 1) % TITLESTACKSIZE;
free(titlestack[tstkin]);
titlestack[tstkin] = titlestack[tstki] ? xstrdup(titlestack[tstki]) : NULL;
tstki = tstkin;
}
int
xstartdraw(void)
{
@@ -1887,6 +1948,18 @@ kpress(XEvent *ev)
== finish) normalMode();
return;
}
/* 0. highlight URLs when control held */
if (ksym == XK_Control_L) {
highlighturls();
} else if (ev->type == KeyRelease && e->keycode == XKeysymToKeycode(e->display, XK_Control_L)) {
unhighlighturls();
}
/* KeyRelease not relevant to shortcuts */
if (ev->type == KeyRelease)
return;
/* 1. shortcuts */
for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
if (ksym == bp->keysym && match(bp->mod, e->state)) {
@@ -2127,13 +2200,14 @@ xrdb_load(void)
defaultrcs = defaultbg;
}
XRESOURCE_LOAD_STRING("font", font);
XRESOURCE_LOAD_STRING("font", fonts[0]);
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_INTEGER("lightmode", lightmode);
XRESOURCE_LOAD_FLOAT("cwscale", cwscale);
XRESOURCE_LOAD_FLOAT("chscale", chscale);
@@ -2149,7 +2223,7 @@ reload(int sig)
/* colors, fonts */
xloadcols();
xunloadfonts();
xloadfonts(font, 0);
xloadfonts(fonts[currentfont], 0);
/* pretend the window just got resized */
cresize(win.w, win.h);