summaryrefslogtreecommitdiffstats
path: root/color.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2021-04-11 15:56:42 -0700
committerKevin McCarthy <kevin@8t8.us>2021-04-15 17:58:56 -0700
commit2d6832011debd96324037eee1ccbdfba1903b197 (patch)
tree0cd343497206be7f78ae89f5311c0326bdaf96a5 /color.c
parentc20a5169f7a3b5525f1d8c0ee4b0743d8358a98c (diff)
Fix ansi colors to use default bg/fg when not set.
Note the ColorList stores COLOR_DEFAULT (-2) not -1, so we need to translate those values in mutt_alloc_ansi_color(). If the curses backend doesn't support default colors, we abort and just return color pair 0.
Diffstat (limited to 'color.c')
-rw-r--r--color.c70
1 files changed, 56 insertions, 14 deletions
diff --git a/color.c b/color.c
index 035e6151..1dec01b2 100644
--- a/color.c
+++ b/color.c
@@ -40,6 +40,10 @@ COLOR_LINE *ColorIndexList = NULL;
/* local to this file */
static int ColorQuoteSize;
+#if defined(HAVE_COLOR) && defined(HAVE_USE_DEFAULT_COLORS)
+static int HaveDefaultColors = 0;
+static int DefaultColorsInit = 0;
+#endif
#ifdef HAVE_COLOR
@@ -172,6 +176,15 @@ static void mutt_free_color_line(COLOR_LINE **l,
FREE (l); /* __FREE_CHECKED__ */
}
+#if defined(HAVE_COLOR) && defined(HAVE_USE_DEFAULT_COLORS)
+static void init_default_colors (void)
+{
+ DefaultColorsInit = 1;
+ if (use_default_colors () == OK)
+ HaveDefaultColors = 1;
+}
+#endif /* defined(HAVE_COLOR) && defined(HAVE_USE_DEFAULT_COLORS) */
+
void ci_start_color (void)
{
memset (ColorDefs, 0, sizeof (COLOR_ATTR) * MT_COLOR_MAX);
@@ -378,16 +391,24 @@ static int _mutt_alloc_color (int fg, int bg, int type)
#if defined (USE_SLANG_CURSES)
if (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT)
- SLtt_set_color (pair, NULL, get_color_name (fgc, sizeof (fgc), fg), get_color_name (bgc, sizeof (bgc), bg));
+ {
+ SLtt_set_color (pair, NULL,
+ get_color_name (fgc, sizeof (fgc), fg),
+ get_color_name (bgc, sizeof (bgc), bg));
+ }
else
+
#elif defined (HAVE_USE_DEFAULT_COLORS)
- if (fg == COLOR_DEFAULT)
- fg = -1;
+ if (fg == COLOR_DEFAULT)
+ fg = -1;
if (bg == COLOR_DEFAULT)
bg = -1;
#endif
- init_pair(p->pair, fg, bg);
+ /* NOTE: this may be the "else" clause of the SLANG #if block above. */
+ {
+ init_pair (p->pair, fg, bg);
+ }
dprint (3, (debugfile,"mutt_alloc_color(): Color pairs used so far: %d\n",
UserColors));
@@ -402,6 +423,24 @@ int mutt_alloc_color (int fg, int bg)
int mutt_alloc_ansi_color (int fg, int bg)
{
+ if (fg == -1 || bg == -1)
+ {
+#if defined (HAVE_USE_DEFAULT_COLORS)
+ if (!DefaultColorsInit)
+ init_default_colors ();
+
+ if (!HaveDefaultColors)
+ return 0;
+#elif !defined (USE_SLANG_CURSES)
+ return 0;
+#endif
+
+ if (fg == -1)
+ fg = COLOR_DEFAULT;
+ if (bg == -1)
+ bg = COLOR_DEFAULT;
+ }
+
return _mutt_alloc_color (fg, bg, MUTT_COLOR_TYPE_ANSI);
}
@@ -984,18 +1023,21 @@ _mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err,
if (dry_run) return 0;
-#ifdef HAVE_COLOR
-# ifdef HAVE_USE_DEFAULT_COLORS
- if (!option (OPTNOCURSES) && has_colors()
- /* delay use_default_colors() until needed, since it initializes things */
- && (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT)
- && use_default_colors () != OK)
+#if defined(HAVE_COLOR) && defined(HAVE_USE_DEFAULT_COLORS)
+ if (!option (OPTNOCURSES) &&
+ has_colors() &&
+ (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT))
{
- strfcpy (err->data, _("default colors not supported"), err->dsize);
- return (-1);
+ /* delay use_default_colors() until needed, since it initializes things */
+ if (!DefaultColorsInit)
+ init_default_colors ();
+ if (!HaveDefaultColors)
+ {
+ strfcpy (err->data, _("default colors not supported"), err->dsize);
+ return (-1);
+ }
}
-# endif /* HAVE_USE_DEFAULT_COLORS */
-#endif
+#endif /* defined(HAVE_COLOR) && defined(HAVE_USE_DEFAULT_COLORS) */
if (object == MT_COLOR_HEADER)
r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err,0);