startup: parse interface colors when they are read, not when initialized

When the palette is getting initialized, it is too late to send any
error messages about the rcfile options to standard error.

This fixes https://savannah.gnu.org/bugs/?52871.
Reported-by: Brand Huntsman <alpha@qzx.com>

Signed-off-by: Brand Huntsman <alpha@qzx.com>
master
Brand Huntsman 2018-01-12 03:47:07 -07:00 committed by Benno Schulenberg
parent 00c1105c1b
commit 4b24ce1c11
4 changed files with 34 additions and 19 deletions

View File

@ -45,7 +45,6 @@ void set_colorpairs(void)
{
const syntaxtype *sint;
bool using_defaults = FALSE;
short foreground, background;
size_t i;
/* Tell ncurses to enable colors. */
@ -58,18 +57,16 @@ void set_colorpairs(void)
/* Initialize the color pairs for nano's interface elements. */
for (i = 0; i < NUMBER_OF_ELEMENTS; i++) {
bool bright = FALSE;
colortype *color = specified_color_combo[i];
if (specified_color_combo[i] != NULL &&
parse_color_names(specified_color_combo[i],
&foreground, &background, &bright)) {
if (foreground == -1 && !using_defaults)
foreground = COLOR_WHITE;
if (background == -1 && !using_defaults)
background = COLOR_BLACK;
init_pair(i + 1, foreground, background);
if (color != NULL) {
if (color->fg == -1 && !using_defaults)
color->fg = COLOR_WHITE;
if (color->bg == -1 && !using_defaults)
color->bg = COLOR_BLACK;
init_pair(i + 1, color->fg, color->bg);
interface_color_pair[i] = COLOR_PAIR(i + 1) | A_BANDAID |
(bright ? A_BOLD : A_NORMAL);
(color->bright ? A_BOLD : A_NORMAL);
} else {
if (i != FUNCTION_TAG)
interface_color_pair[i] = hilite_attribute;

View File

@ -233,7 +233,7 @@ regmatch_t regmatches[10];
int hilite_attribute = A_REVERSE;
/* The curses attribute we use to highlight something. */
#ifdef ENABLE_COLOR
char* specified_color_combo[] = {NULL};
colortype* specified_color_combo[] = {NULL};
/* The color combinations as specified in the rcfile. */
#endif
int interface_color_pair[] = {0};

View File

@ -172,7 +172,7 @@ extern regmatch_t regmatches[10];
extern int hilite_attribute;
#ifdef ENABLE_COLOR
extern char* specified_color_combo[NUMBER_OF_ELEMENTS];
extern colortype* specified_color_combo[NUMBER_OF_ELEMENTS];
#endif
extern int interface_color_pair[NUMBER_OF_ELEMENTS];

View File

@ -774,6 +774,24 @@ bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright)
return TRUE;
}
/* Parse interface color options. */
colortype *parse_interface_color(char *combostr)
{
short fg, bg;
bool bright = FALSE;
colortype *newcolor;
if (!parse_color_names(combostr, &fg, &bg, &bright))
return NULL;
newcolor = (colortype *)nmalloc(sizeof(colortype));
newcolor->fg = fg;
newcolor->bg = bg;
newcolor->bright = bright;
return newcolor;
}
/* Read regex strings enclosed in double quotes from the line pointed at
* by ptr, and store them quoteless in the passed storage place. */
void grab_and_store(const char *kind, char *ptr, regexlisttype **storage)
@ -1086,17 +1104,17 @@ void parse_rcfile(FILE *rcstream, bool syntax_only)
#ifdef ENABLE_COLOR
if (strcasecmp(rcopts[i].name, "titlecolor") == 0)
specified_color_combo[TITLE_BAR] = option;
specified_color_combo[TITLE_BAR] = parse_interface_color(option);
else if (strcasecmp(rcopts[i].name, "numbercolor") == 0)
specified_color_combo[LINE_NUMBER] = option;
specified_color_combo[LINE_NUMBER] = parse_interface_color(option);
else if (strcasecmp(rcopts[i].name, "selectedcolor") == 0)
specified_color_combo[SELECTED_TEXT] = option;
specified_color_combo[SELECTED_TEXT] = parse_interface_color(option);
else if (strcasecmp(rcopts[i].name, "statuscolor") == 0)
specified_color_combo[STATUS_BAR] = option;
specified_color_combo[STATUS_BAR] = parse_interface_color(option);
else if (strcasecmp(rcopts[i].name, "keycolor") == 0)
specified_color_combo[KEY_COMBO] = option;
specified_color_combo[KEY_COMBO] = parse_interface_color(option);
else if (strcasecmp(rcopts[i].name, "functioncolor") == 0)
specified_color_combo[FUNCTION_TAG] = option;
specified_color_combo[FUNCTION_TAG] = parse_interface_color(option);
else
#endif
#ifdef ENABLE_OPERATINGDIR