Commit 4b24ce1c authored by Brand Huntsman's avatar Brand Huntsman Committed by Benno Schulenberg
Browse files

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: default avatarBrand Huntsman <alpha@qzx.com>
Signed-off-by: default avatarBrand Huntsman <alpha@qzx.com>
No related merge requests found
Showing with 35 additions and 20 deletions
+35 -20
......@@ -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;
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);
colortype *color = specified_color_combo[i];
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;
......
......@@ -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};
......
......@@ -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];
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment