From bda5b50b99fa06739fb2d370ff033bff54703108 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Mon, 20 Apr 2020 12:35:11 +0200 Subject: [PATCH] [st][PATCH] OSC 10/11/12 fg, bg and cursor colors Support for OSC escape sequences 10, 11 and 12 to modify the bg, fg and cursor colors. I selected entries in the colorname table after the 255 position for defaultfg, defaultbg and defaultcs --- config.def.h | 4 ++-- st.c | 17 ++++++++++++++--- st.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/config.def.h b/config.def.h index da02472..940321b 100644 --- a/config.def.h +++ b/config.def.h @@ -187,8 +187,8 @@ unsigned int defaultbg = 258; #else unsigned int defaultbg = 0; #endif // ALPHA_PATCH -static unsigned int defaultcs = 256; -static unsigned int defaultrcs = 257; +unsigned int defaultcs = 256; +unsigned int defaultrcs = 257; /* * Default shape of cursor diff --git a/st.c b/st.c index 7e493bd..1a1aea1 100644 --- a/st.c +++ b/st.c @@ -2009,12 +2009,23 @@ strhandle(void) } return; case 4: /* color set */ - if (narg < 3) + case 10: /* foreground set */ + case 11: /* background set */ + case 12: /* cursor color */ + if ((par == 4 && narg < 3) || narg < 2) break; - p = strescseq.args[2]; + p = strescseq.args[((par == 4) ? 2 : 1)]; /* FALLTHROUGH */ case 104: /* color reset, here p = NULL */ - j = (narg > 1) ? atoi(strescseq.args[1]) : -1; + if (par == 10) + j = defaultfg; + else if (par == 11) + j = defaultbg; + else if (par == 12) + j = defaultcs; + else + j = (narg > 1) ? atoi(strescseq.args[1]) : -1; + if (xsetcolorname(j, p)) { if (par == 104 && narg <= 1) return; /* color reset without parameter */ diff --git a/st.h b/st.h index 030de38..525812d 100644 --- a/st.h +++ b/st.h @@ -141,6 +141,7 @@ extern char *termname; extern unsigned int tabspaces; extern unsigned int defaultfg; extern unsigned int defaultbg; +extern unsigned int defaultcs; #if BOXDRAW_PATCH extern const int boxdraw, boxdraw_bold, boxdraw_braille; #endif // BOXDRAW_PATCH