[hackers] [st][PATCH 2/2] Allow cursor color to follow text color

From: Jules Maselbas <jules.maselbas_AT_grenoble-inp.org>
Date: Wed, 4 Jul 2018 15:37:53 +0200

To set cursor color to following underling text color, you need to
set defaultcs/defaultrcs to a negative value.

---
 config.def.h |  4 ++--
 x.c          | 21 +++++++++++++++++----
 2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/config.def.h b/config.def.h
index 82b1b09..8b9262b 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -118,8 +118,8 @@ static const char *colorname[] = {
  */
 unsigned int defaultfg = 7;
 unsigned int defaultbg = 0;
-static unsigned int defaultcs = 256;
-static unsigned int defaultrcs = 257;
+static int defaultcs = 256;
+static int defaultrcs = 257;
 
 /*
  * Default shape of cursor
diff --git a/x.c b/x.c
index d8ca4d4..98a4b1f 100644
--- a/x.c
+++ b/x.c
_AT_@ -1400,6 +1400,7 @@ void
 xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
 {
 	Color drawcol;
+	int tmp;
 
 	/* remove the old cursor */
 	if (selected(ox, oy))
_AT_@ -1415,11 +1416,23 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
 	g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE;
 
 	if (selected(cx, cy)) {
-		g.bg = defaultrcs;
-		g.fg = defaultfg;
+		if (defaultrcs > 0) {
+			g.bg = defaultrcs;
+			g.fg = defaultfg;
+		}
 	} else {
-		g.bg = defaultcs;
-		g.fg = defaultbg;
+		if (defaultcs > 0) {
+			g.bg = defaultcs;
+			g.fg = defaultbg;
+		} else {
+			tmp = g.bg;
+			g.bg = g.fg;
+			if (g.mode & ATTR_BOLD && BETWEEN(g.bg, 0, 7)) {
+				g.bg += 8;
+				g.mode |= ATTR_FAINT;
+			}
+			g.fg = tmp;
+		}
 	}
 	drawcol = dc.col[g.bg];
 
-- 
2.18.0
Received on Wed Jul 04 2018 - 15:37:53 CEST

This archive was generated by hypermail 2.3.0 : Wed Jul 04 2018 - 15:48:26 CEST