commit b87cac58b367f0cc3e904f4f4cd83a60faaeb303
Author: Santtu Lakkala <[email protected]>
Date:   Wed Feb 23 17:04:26 2022 +0200

    [dwm][patch][sgrstatus] CSI SGR sequence support
    
    This patch allows the use of quasi-standard CSI SGR escape sequences to
    alter the formatting of the status bar.

diff --git a/dwm.suckless.org/patches/sgrstatus/dwm-sgrstatus-20220223-6.3.diff 
b/dwm.suckless.org/patches/sgrstatus/dwm-sgrstatus-20220223-6.3.diff
new file mode 100644
index 00000000..c033ba48
--- /dev/null
+++ b/dwm.suckless.org/patches/sgrstatus/dwm-sgrstatus-20220223-6.3.diff
@@ -0,0 +1,265 @@
+From dc83e43aad7b8070911e8210b58cc36bdc4214d5 Mon Sep 17 00:00:00 2001
+From: Santtu Lakkala <[email protected]>
+Date: Wed, 23 Feb 2022 11:55:19 +0200
+Subject: [PATCH 1/2] Allow CSI SGR in status bar
+
+---
+ config.def.h |  19 ++++++
+ dwm.c        | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++-
+ 2 files changed, 198 insertions(+), 3 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index a2ac963..3dc34bd 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -18,6 +18,25 @@ static const char *colors[][3]      = {
+       [SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
+ };
+ 
++static const char *barcolors[] = {
++      "#000000",
++      "#7f0000",
++      "#007f00",
++      "#7f7f00",
++      "#00007f",
++      "#7f007f",
++      "#007f7f",
++      "#cccccc",
++      "#333333",
++      "#ff0000",
++      "#00ff00",
++      "#ffff00",
++      "#0000ff",
++      "#ff00ff",
++      "#00ffff",
++      "#ffffff",
++};
++
+ /* tagging */
+ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+ 
+diff --git a/dwm.c b/dwm.c
+index a96f33c..cb9484a 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -237,7 +237,7 @@ static void zoom(const Arg *arg);
+ 
+ /* variables */
+ static const char broken[] = "broken";
+-static char stext[256];
++static char stext[512];
+ static int screen;
+ static int sw, sh;           /* X display screen geometry width, height */
+ static int bh, blw = 0;      /* bar geometry */
+@@ -264,6 +264,7 @@ static Atom wmatom[WMLast], netatom[NetLast];
+ static int running = 1;
+ static Cur *cursor[CurLast];
+ static Clr **scheme;
++static Clr *barclrs;
+ static Display *dpy;
+ static Drw *drw;
+ static Monitor *mons, *selmon;
+@@ -693,6 +694,25 @@ dirtomon(int dir)
+       return m;
+ }
+ 
++void
++resetfntlist(Fnt *orighead, Fnt *curhead)
++{
++      if (orighead != curhead) {
++              Fnt *f;
++              for (f = orighead; f->next; f = f->next);
++              f->next = curhead;
++              for (f = f->next; f->next != orighead; f = f->next);
++              f->next = NULL;
++      }
++}
++
++enum SgrFlags {
++      REVERSE = 1 << 0,
++      UNDERLINE = 1 << 1,
++      STRIKETHROUGH = 1 << 2,
++      OVERLINE = 1 << 3
++};
++
+ void
+ drawbar(Monitor *m)
+ {
+@@ -707,9 +727,160 @@ drawbar(Monitor *m)
+ 
+       /* draw status first so it can be overdrawn by tags later */
+       if (m == selmon) { /* status is only drawn on selected monitor */
++              char buffer[sizeof(stext)];
++              Clr scm[3];
++              int wr, rd;
++              int pw;
++              int fg = 7;
++              int bg = 0;
++              int fmt = 0;
++              int lp = lrpad / 2 - 2;
++              Fnt *fset = drw->fonts;
++
++              memcpy(scm, scheme[SchemeNorm], sizeof(scm));
++
++              drw_setscheme(drw, scm);
++
++              for (tw = 0, wr = 0, rd = 0; stext[rd]; rd++) {
++                      if (stext[rd] == '' && stext[rd + 1] == '[') {
++                              size_t alen = strspn(stext + rd + 2,
++                                                   "0123456789;");
++                              if (stext[rd + alen + 2] == 'm') {
++                                      buffer[wr] = '++                        
                tw += TEXTW(buffer) - lrpad;
++                                      wr = 0;
++
++                                      char *ep = stext + rd + 1;
++                                      while (*ep != 'm') {
++                                              unsigned v = strtoul(ep + 1, 
&ep, 10);
++                                              if (v == 0 || (v >= 10 && v <= 
19)) {
++                                                      int fi = v % 10;
++                                                      Fnt *f;
++                                                      Fnt *p;
++                                                      resetfntlist(fset, 
drw->fonts);
++                                                      for (p = NULL, f = 
fset; f && fi--; p = f, f = f->next);
++                                                      if (f) {
++                                                              if (p) {
++                                                                      p->next 
= NULL;
++                                                                      for (p 
= f; p->next; p = p->next);
++                                                                      p->next 
= fset;
++                                                              }
++                                                              
drw_setfontset(drw, f);
++                                                      } else {
++                                                              
drw_setfontset(drw, fset);
++                                                      }
++                                              }
++                                      }
++
++                                      rd += alen + 2;
++                                      continue;
++                              }
++                      }
++                      buffer[wr++] = stext[rd];
++              }
++              buffer[wr] = '++
++              tw += TEXTW(buffer) - lrpad / 2 + 2;
++              x = m->ww - tw;
++
++              resetfntlist(fset, drw->fonts);
++              drw_setfontset(drw, fset);
++
++              for (wr = 0, rd = 0; stext[rd]; rd++) {
++                      if (stext[rd] == '' && stext[rd + 1] == '[') {
++                              size_t alen = strspn(stext + rd + 2,
++                                                   "0123456789;");
++                              if (stext[rd + alen + 2] == 'm') {
++                                      buffer[wr] = '++                        
                pw = TEXTW(buffer) - lrpad;
++                                      drw_text(drw, x, 0, pw + lp, bh, lp, 
buffer, fmt & REVERSE);
++                                      if (fmt & UNDERLINE)
++                                              drw_rect(drw, x, (bh + 
drw->fonts->h) / 2, pw, 1, 1, fmt & REVERSE); 
++                                      if (fmt & STRIKETHROUGH)
++                                              drw_rect(drw, x, bh / 2, pw, 1, 
1, fmt & REVERSE); 
++                                      if (fmt & OVERLINE)
++                                              drw_rect(drw, x, (bh - 
drw->fonts->h) / 2, pw, 1, 1, fmt & REVERSE); 
++                                      x += pw + lp;
++                                      lp = 0;
++
++                                      char *ep = stext + rd + 1;
++                                      while (*ep != 'm') {
++                                              unsigned v = strtoul(ep + 1, 
&ep, 10);
++                                              if (v == 0) {
++                                                      memcpy(scm, 
scheme[SchemeNorm], sizeof(scm));
++                                                      fg = 7;
++                                                      bg = 0;
++                                                      fmt = 0;
++                                                      resetfntlist(fset, 
drw->fonts);
++                                                      drw_setfontset(drw, 
fset);
++                                              } else if (v == 1) {
++                                                      fg |= 8;
++                                                      scm[0] = barclrs[fg];
++                                              } else if (v == 4) {
++                                                      fmt |= UNDERLINE;
++                                              } else if (v == 7) {
++                                                      fmt |= REVERSE;
++                                              } else if (v == 9) {
++                                                      fmt |= STRIKETHROUGH;
++                                              } else if (v >= 10 && v <= 19) {
++                                                      int fi = v % 10;
++                                                      Fnt *f;
++                                                      Fnt *p;
++                                                      resetfntlist(fset, 
drw->fonts);
++                                                      for (p = NULL, f = 
fset; f && fi--; p = f, f = f->next);
++                                                      if (f) {
++                                                              if (p) {
++                                                                      p->next 
= NULL;
++                                                                      for (p 
= f; p->next; p = p->next);
++                                                                      p->next 
= fset;
++                                                              }
++                                                              
drw_setfontset(drw, f);
++                                                      } else {
++                                                              
drw_setfontset(drw, fset);
++                                                      }
++                                              } else if (v == 22) {
++                                                      fg &= ~8;
++                                                      scm[0] = barclrs[fg];
++                                              } else if (v == 24) {
++                                                      fmt &= ~UNDERLINE;
++                                              } else if (v == 27) {
++                                                      fmt &= ~REVERSE;
++                                              } else if (v == 29) {
++                                                      fmt &= ~STRIKETHROUGH;
++                                              } else if (v >= 30 && v <= 37) {
++                                                      fg = v % 10 | (fg & 8);
++                                                      scm[0] = barclrs[fg];
++                                              } else if (v >= 40 && v <= 47) {
++                                                      bg = v % 10;
++                                                      scm[1] = barclrs[bg];
++                                              } else if (v == 53) {
++                                                      fmt |= OVERLINE;
++                                              } else if (v == 55) {
++                                                      fmt &= ~OVERLINE;
++                                              }
++                                      }
++
++                                      rd += alen + 2;
++                                      wr = 0;
++
++                                      drw_setscheme(drw, scm);
++                                      continue;
++                              }
++                      }
++                      buffer[wr++] = stext[rd];
++              }
++
++              buffer[wr] = '++                pw = TEXTW(buffer) - lrpad;
++              drw_text(drw, x, 0, pw + lp, bh, lp, buffer, fmt & REVERSE);
++              if (fmt & UNDERLINE)
++                      drw_rect(drw, x, (bh + drw->fonts->h) / 2, pw, 1, 1, 
fmt & REVERSE); 
++              if (fmt & STRIKETHROUGH)
++                      drw_rect(drw, x, bh / 2, pw, 1, 1, fmt & REVERSE); 
++              if (fmt & OVERLINE)
++                      drw_rect(drw, x, (bh - drw->fonts->h) / 2, pw, 1, 1, 
fmt & REVERSE); 
++
+               drw_setscheme(drw, scheme[SchemeNorm]);
+-              tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
+-              drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
+       }
+ 
+       for (c = m->clients; c; c = c->next) {
+@@ -1574,6 +1745,11 @@ setup(void)
+       scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
+       for (i = 0; i < LENGTH(colors); i++)
+               scheme[i] = drw_scm_create(drw, colors[i], 3);
++
++      barclrs = ecalloc(LENGTH(barcolors), sizeof(Clr));
++      for (i = 0; i < LENGTH(barcolors); i++)
++              drw_clr_create(drw, &barclrs[i], barcolors[i]);
++
+       /* init bars */
+       updatebars();
+       updatestatus();
+-- 
+2.32.0
+
diff --git 
a/dwm.suckless.org/patches/sgrstatus/dwm-sgrstatus256-20220223-6.3.diff 
b/dwm.suckless.org/patches/sgrstatus/dwm-sgrstatus256-20220223-6.3.diff
new file mode 100644
index 00000000..116eeb8a
--- /dev/null
+++ b/dwm.suckless.org/patches/sgrstatus/dwm-sgrstatus256-20220223-6.3.diff
@@ -0,0 +1,130 @@
+From 7be41dd26e562072afc11621432aa71d2ea5622a Mon Sep 17 00:00:00 2001
+From: Santtu Lakkala <[email protected]>
+Date: Wed, 23 Feb 2022 16:22:59 +0200
+Subject: [PATCH 2/2] 256 colors SGR support
+
+---
+ dwm.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
+ 1 file changed, 64 insertions(+), 3 deletions(-)
+
+diff --git a/dwm.c b/dwm.c
+index cb9484a..e2dc586 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -264,7 +264,7 @@ static Atom wmatom[WMLast], netatom[NetLast];
+ static int running = 1;
+ static Cur *cursor[CurLast];
+ static Clr **scheme;
+-static Clr *barclrs;
++static Clr barclrs[256];
+ static Display *dpy;
+ static Drw *drw;
+ static Monitor *mons, *selmon;
+@@ -804,8 +804,25 @@ drawbar(Monitor *m)
+                                       lp = 0;
+ 
+                                       char *ep = stext + rd + 1;
++                                      int ignore = 0;
++                                      int bgfg = 0;
+                                       while (*ep != 'm') {
+                                               unsigned v = strtoul(ep + 1, 
&ep, 10);
++                                              if (ignore)
++                                                      continue;
++                                              if (bgfg) {
++                                                      if (bgfg < 4 && v == 5) 
{
++                                                              bgfg <<= 1;
++                                                              continue;
++                                                      }
++                                                      if (bgfg == 4)
++                                                              scm[0] = 
barclrs[fg = v];
++                                                      else if (bgfg == 6)
++                                                              scm[1] = 
barclrs[bg = v];
++                                                      ignore = 1;
++
++                                                      continue;
++                                              }
+                                               if (v == 0) {
+                                                       memcpy(scm, 
scheme[SchemeNorm], sizeof(scm));
+                                                       fg = 7;
+@@ -850,9 +867,13 @@ drawbar(Monitor *m)
+                                               } else if (v >= 30 && v <= 37) {
+                                                       fg = v % 10 | (fg & 8);
+                                                       scm[0] = barclrs[fg];
++                                              } else if (v == 38) {
++                                                      bgfg = 2;
+                                               } else if (v >= 40 && v <= 47) {
+                                                       bg = v % 10;
+                                                       scm[1] = barclrs[bg];
++                                              } else if (v == 48) {
++                                                      bgfg = 3;
+                                               } else if (v == 53) {
+                                                       fmt |= OVERLINE;
+                                               } else if (v == 55) {
+@@ -1701,12 +1722,19 @@ setmfact(const Arg *arg)
+       arrange(selmon);
+ }
+ 
++unsigned char
++sixd_to_8bit(int x)
++{
++      return x == 0 ? 0 : 0x37 + 0x28 * x;
++}
++
+ void
+ setup(void)
+ {
+       int i;
+       XSetWindowAttributes wa;
+       Atom utf8string;
++      char cbuf[8];
+ 
+       /* clean up any zombies immediately */
+       sigchld(0);
+@@ -1746,9 +1774,42 @@ setup(void)
+       for (i = 0; i < LENGTH(colors); i++)
+               scheme[i] = drw_scm_create(drw, colors[i], 3);
+ 
+-      barclrs = ecalloc(LENGTH(barcolors), sizeof(Clr));
+-      for (i = 0; i < LENGTH(barcolors); i++)
++      for (i = 0; i < LENGTH(barcolors) && i < LENGTH(barclrs); i++)
+               drw_clr_create(drw, &barclrs[i], barcolors[i]);
++      if (i == 0)
++              drw_clr_create(drw, &barclrs[i++], "#000000");
++      for (; i < 7; i++) {
++              snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x",
++                       !!(i & 1) * 0x7f,
++                       !!(i & 2) * 0x7f,
++                       !!(i & 4) * 0x7f);
++              drw_clr_create(drw, &barclrs[i], cbuf);
++      }
++      if (i == 7)
++              drw_clr_create(drw, &barclrs[i++], "#000000");
++      if (i == 8)
++              drw_clr_create(drw, &barclrs[i++], "#333333");
++      for (; i < 16; i++) {
++              snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x",
++                       !!(i & 1) * 0xff,
++                       !!(i & 2) * 0xff,
++                       !!(i & 4) * 0xff);
++              drw_clr_create(drw, &barclrs[i], cbuf);
++      }
++      for (; i < 6 * 6 * 6 + 16; i++) {
++              snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x",
++                       sixd_to_8bit(((i - 16) / 36) % 6),
++                       sixd_to_8bit(((i - 16) / 6) % 6),
++                       sixd_to_8bit(((i - 16)) % 6));
++              drw_clr_create(drw, &barclrs[i], cbuf);
++      }
++      for (; i < 256; i++) {
++              snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x",
++                       0x08 + (i - 6 * 6 * 6 - 16) * 0x0a,
++                       0x08 + (i - 6 * 6 * 6 - 16) * 0x0a,
++                       0x08 + (i - 6 * 6 * 6 - 16) * 0x0a);
++              drw_clr_create(drw, &barclrs[i], cbuf);
++      }
+ 
+       /* init bars */
+       updatebars();
+-- 
+2.32.0
+
diff --git a/dwm.suckless.org/patches/sgrstatus/index.md 
b/dwm.suckless.org/patches/sgrstatus/index.md
new file mode 100644
index 00000000..0e52cbba
--- /dev/null
+++ b/dwm.suckless.org/patches/sgrstatus/index.md
@@ -0,0 +1,61 @@
+SGR in status text
+==================
+
+Description
+-----------
+Allows the use of CSI SGR escape sequences in the status bar text to change
+text rendition. Currently supported are:
+
+* color changes (either 16 or 256, depending on chosen patch)
+* alternate font (ones listed in fonts[] array)
+* reverse, underline, strikethrough, overline
+
+Configuration
+-------------
+Download the patch and apply it according to the [general instructions](../).
+
+Modify the barcolors definition in 'config.h' to suit your needs. For the 16
+color version, you should have at least 16 colors defined.
+
+Usage
+-----
+Add code to your status script to output CSI SGR codes. They take the form
+ESC[1;2;3;4m.
+
+* 0 resets all formatting
+* 1 makes text bright (_not_ bold)
+* 4 underlines
+* 7 reverses
+* 9 strike-through's
+* 10-19 alternate font
+* 53 overlines
+* 30-37 sets foreground color
+* 40-47 sets background color
+
+In addition the 256 color version allows the use of: `ESC[38;5;123m` to set
+foreground to color 123 (48 changes background).
+
+### Example
+
+With slstatus, you can have your date in bright red using:
+
+       { datetime, "%s\e[0m",           "%F %T" },
+
+For a more pointless example, you could combine slstatus -s with
+[nyancat](https://inzg.it/nyancat/):
+
+       slstatus -s | nyancat -2 | while read l; do xsetroot -name "$l"; done
+
+And you'll get something like ![rainbow status](nyanstatus.png).
+
+Download
+--------
+* [dwm-sgrstatus-20220223-6.3.diff](dwm-sgrstatus-20220223-6.3.diff)
+
+For 256 color support, apply the following on top:
+
+* [dwm-sgrstatus256-20220223-6.3.diff](dwm-sgrstatus256-20220223-6.3.diff)
+
+Authors
+-------
+* Santtu Lakkala - <[email protected]>
diff --git a/dwm.suckless.org/patches/sgrstatus/nyanstatus.png 
b/dwm.suckless.org/patches/sgrstatus/nyanstatus.png
new file mode 100644
index 00000000..1ff0c11c
Binary files /dev/null and b/dwm.suckless.org/patches/sgrstatus/nyanstatus.png 
differ


Reply via email to