The background/foreground of selected text is currently set by setting
ATTR_REVERSE, which flips its normal bg/fg. When the text being
selected has the same bg and fg, it won't be readable after selecting
it, either.

This may sound silly - my main use case is IRC channels using color
codes for black-on-black to mark 'spoilers'.

This patch allows that text to be read by selecting it, turning it
into text with white bg and black fg (given default values for
defaultbg/fg), just like most normal unformatted text when selected.
From 380f8ba874976a8392d9c2a6639775b45fce5d91 Mon Sep 17 00:00:00 2001
From: dequis <d...@dxzone.com.ar>
Date: Sun, 26 Oct 2014 22:39:46 -0300
Subject: [PATCH] Use inverted defaultbg/fg for selection when bg/fg are the
 same

The background/foreground of selected text is currently set by setting
ATTR_REVERSE, which flips its normal bg/fg. When the text being selected
has the same bg and fg, it won't be readable after selecting it, either.

This may sound silly - my main use case is IRC channels using color
codes for black-on-black to mark 'spoilers'.

This patch allows that text to be read by selecting it, turning it into
text with white bg and black fg (given default values for defaultbg/fg),
just like most normal unformatted text when selected.
---
 st.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/st.c b/st.c
index 12af1ab..e2b7003 100644
--- a/st.c
+++ b/st.c
@@ -3296,9 +3296,14 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 	}
 
 	if(base.mode & ATTR_REVERSE) {
-		temp = fg;
-		fg = bg;
-		bg = temp;
+		if (bg == fg) {
+			bg = &dc.col[defaultfg];
+			fg = &dc.col[defaultbg];
+		} else {
+			temp = fg;
+			fg = bg;
+			bg = temp;
+		}
 	}
 
 	if(base.mode & ATTR_FAINT && !(base.mode & ATTR_BOLD)) {
-- 
2.1.2

Reply via email to