[misc] [PATCH] Default colour as foreground colour

In the default colour setup (white on black), white could only
with great difficulty be used as customized foreground colour,
because the colour pair COLR_CUSTOM then was identical to
COLR_DEFAULT (default on default). This made it impossible to
distinguish the selected element in lists.

The patch turns on the video attribute bold when default is chosen
as foreground colour.
---
Apart from not treating white exceptionally, some comments were
clarified (hopefully).

 src/calcurse.h |  6 +++++-
 src/config.c   |  1 +
 src/custom.c   | 15 ++++++++++++---
 src/utils.c    |  6 ++++++
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/calcurse.h b/src/calcurse.h
index 82c0246..433b0eb 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -677,7 +677,11 @@ enum move {
 	YEAR_NEXT
 };
 
-/* Available color pairs. */
+/*
+ * Available color pairs.
+ * The numbering must agree with
+ * the colour numbers 1-6, see custom.c.
+ */
 enum {
 	COLR_RED = 1,
 	COLR_GREEN,
diff --git a/src/config.c b/src/config.c
index f8eee98..1e11668 100644
--- a/src/config.c
+++ b/src/config.c
@@ -265,6 +265,7 @@ static int config_parse_color_theme(void *dummy, const char *val)
 	if (!config_parse_color_pair(&color1, &color2, val))
 		return 0;
 	init_pair(COLR_CUSTOM, color1, color2);
+	custom_init_attr();
 	return 1;
 }
 
diff --git a/src/custom.c b/src/custom.c
index 65b4d4d..6961e38 100644
--- a/src/custom.c
+++ b/src/custom.c
@@ -58,7 +58,13 @@ static struct attribute attr;
  */
 void custom_init_attr(void)
 {
-	attr.color[ATTR_HIGHEST] = COLOR_PAIR(COLR_CUSTOM);
+	short col_fg;
+	pair_content(COLR_CUSTOM, &col_fg, NULL);
+
+	attr.color[ATTR_HIGHEST] =
+		(col_fg == -1 || col_fg == 255) ?
+		COLOR_PAIR(COLR_CUSTOM) | A_BOLD :
+		COLOR_PAIR(COLR_CUSTOM);
 	attr.color[ATTR_HIGH] = COLOR_PAIR(COLR_HIGH);
 	attr.color[ATTR_MIDDLE] = COLOR_PAIR(COLR_RED) | A_BOLD;
 	attr.color[ATTR_LOW] = COLOR_PAIR(COLR_CYAN);
@@ -521,6 +527,7 @@ display_color_config(struct window *cwin, int *mark_fore, int *mark_back,
 			if (colr_back == 255)
 				colr_back = -1;
 			init_pair(COLR_CUSTOM, colr_fore, colr_back);
+			custom_init_attr();
 		} else {
 			/* Retrieve the actual color theme. */
 			pair_content(COLR_CUSTOM, &colr_fore, &colr_back);
@@ -529,7 +536,8 @@ display_color_config(struct window *cwin, int *mark_fore, int *mark_back,
 			    || (colr_fore == DEFAULTCOLOR_EXT)) {
 				*mark_fore = NBUSERCOLORS;
 			} else {
-				for (i = 0; i < NBUSERCOLORS + 1; i++)
+				for (i = 0; i < NBUSERCOLORS; i++)
+				/* WARNING. Colour pair number used as colour number. */
 					if (colr_fore == colr[i])
 						*mark_fore = i;
 			}
@@ -538,7 +546,8 @@ display_color_config(struct window *cwin, int *mark_fore, int *mark_back,
 			    || (colr_back == DEFAULTCOLOR_EXT)) {
 				*mark_back = SIZE - 1;
 			} else {
-				for (i = 0; i < NBUSERCOLORS + 1; i++)
+				for (i = 0; i < NBUSERCOLORS; i++)
+				/* WARNING. Colour pair number used as colour number. */
 					if (colr_back ==
 					    colr[NBUSERCOLORS + 1 + i])
 						*mark_back =
diff --git a/src/utils.c b/src/utils.c
index 615174d..b35ef86 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -672,6 +672,12 @@ print_bool_option_incolor(WINDOW * win, unsigned option, int pos_y,
 		EXIT(_("option not defined"));
 	}
 
+	/*
+	 * Possibly nested custom_apply_attr() calls. Turn
+	 * custom_apply_attr(ATTR_HIGHEST) off explicitly,
+	 * while it may have other attributes besides the colour.
+	 */
+	custom_remove_attr(win, ATTR_HIGHEST);
 	custom_apply_attr(win, color);
 	mvwaddstr(win, pos_y, pos_x, option_value);
 	custom_remove_attr(win, color);
-- 
2.14.2.666.gea220ee40

Links