Index: src/global.c =================================================================== --- src/global.c (revisión: 4826) +++ src/global.c (copia de trabajo) @@ -205,6 +205,12 @@ int reverse_attr = A_REVERSE; /* The curses attribute we use for reverse video. */ +#ifndef DISABLE_COLOR +char* specified_color_combo[] = {NULL}; + /* The color combinations as specified in the rcfile. */ +#endif +int interface_color_pair[] = {NULL}; + /* The processed color pairs for the interface elements. */ char *homedir = NULL; /* The user's home directory, from $HOME or /etc/passwd. */ Index: src/nano.h =================================================================== --- src/nano.h (revisión: 4826) +++ src/nano.h (copia de trabajo) @@ -479,6 +479,15 @@ /* Next item in the list. */ } subnfunc; +/* The elements of the interface that can be colored differently. */ +enum +{ + TITLE_BAR = 0, + STATUS_BAR, + KEY_COMBO, + FUNCTION_TAG, + NUMBER_OF_ELEMENTS +}; /* Enumeration to be used in flags table. See FLAGBIT and FLAGOFF * definitions. */ Index: src/rcfile.c =================================================================== --- src/rcfile.c (revisión: 4826) +++ src/rcfile.c (copia de trabajo) @@ -100,6 +100,12 @@ {"wordbounds", WORD_BOUNDS}, {"softwrap", SOFTWRAP}, #endif +#ifndef DISABLE_COLOR + {"titlecolor", 0}, + {"statuscolor", 0}, + {"keycolor", 0}, + {"functioncolor", 0}, +#endif {NULL, 0} }; @@ -703,7 +709,7 @@ void parse_colors(char *ptr, bool icase) { short fg, bg; - bool bright = FALSE, no_fgcolor = FALSE; + bool bright = FALSE; char *fgstr; assert(ptr != NULL); @@ -721,37 +727,9 @@ fgstr = ptr; ptr = parse_next_word(ptr); + if (!parse_color_names(fgstr, &fg, &bg, &bright)) + return; - if (strchr(fgstr, ',') != NULL) { - char *bgcolorname; - - strtok(fgstr, ","); - bgcolorname = strtok(NULL, ","); - if (bgcolorname == NULL) { - /* If we have a background color without a foreground color, - * parse it properly. */ - bgcolorname = fgstr + 1; - no_fgcolor = TRUE; - } - if (strncasecmp(bgcolorname, "bright", 6) == 0) { - rcfile_error( - N_("Background color \"%s\" cannot be bright"), - bgcolorname); - return; - } - bg = color_to_short(bgcolorname, &bright); - } else - bg = -1; - - if (!no_fgcolor) { - fg = color_to_short(fgstr, &bright); - - /* Don't try to parse screwed-up foreground colors. */ - if (fg == -1) - return; - } else - fg = -1; - if (*ptr == '\0') { rcfile_error(N_("Missing regex string")); return; @@ -862,6 +840,44 @@ } } +/* Parse the color name, or pair of color names, in combostr. */ +bool parse_color_names(const char *combostr, short *fg, short *bg, bool *bright) +{ + bool no_fgcolor = FALSE; + + if (combostr == NULL) + return false; + + if (strchr(combostr, ',') != NULL) { + char *bgcolorname; + strtok(combostr, ","); + bgcolorname = strtok(NULL, ","); + if (bgcolorname == NULL) { + /* If we have a background color without a foreground color, + * parse it properly. */ + bgcolorname = combostr + 1; + no_fgcolor = TRUE; + } + if (strncasecmp(bgcolorname, "bright", 6) == 0) { + rcfile_error(N_("Background color \"%s\" cannot be bright"), bgcolorname); + return false; + } + *bg = color_to_short(bgcolorname, bright); + } else + *bg = -1; + + if (!no_fgcolor) { + *fg = color_to_short(combostr, bright); + + /* Don't try to parse screwed-up foreground colors. */ + if (*fg == -1) + return false; + } else + *fg = -1; + + return true; +} + /* Parse the header-line regex that may influence the choice of syntax. */ void parse_headers(char *ptr) { @@ -1149,6 +1165,17 @@ break; } +#ifndef DISABLE_COLOR + if (strcasecmp(rcopts[i].name, "titlecolor") == 0) + specified_color_combo[TITLE_BAR] = option; + else if (strcasecmp(rcopts[i].name, "statuscolor") == 0) + specified_color_combo[STATUS_BAR] = option; + else if (strcasecmp(rcopts[i].name, "keycolor") == 0) + specified_color_combo[KEY_COMBO] = option; + else if (strcasecmp(rcopts[i].name, "functioncolor") == 0) + specified_color_combo[FUNCTION_TAG] = option; + else +#endif #ifndef DISABLE_OPERATINGDIR if (strcasecmp(rcopts[i].name, "operatingdir") == 0) operating_dir = option; @@ -1357,10 +1384,6 @@ while (getchar() != '\n') ; } - -#ifndef DISABLE_COLOR - set_colorpairs(); -#endif } #endif /* !DISABLE_NANORC */ Index: src/proto.h =================================================================== --- src/proto.h (revisión: 4826) +++ src/proto.h (copia de trabajo) @@ -131,6 +131,10 @@ #endif extern int reverse_attr; +#ifndef DISABLE_COLOR +extern char* specified_color_combo[NUMBER_OF_ELEMENTS]; +#endif +extern int interface_color_pair[NUMBER_OF_ELEMENTS]; extern char *homedir; @@ -551,6 +555,7 @@ void parse_include(char *ptr); short color_to_short(const char *colorname, bool *bright); void parse_colors(char *ptr, bool icase); +bool parse_color_names(const char *combostr, short *fg, short *bg, bool *bright); void reset_multis(filestruct *fileptr, bool force); void alloc_multidata_if_needed(filestruct *fileptr); #endif Index: src/color.c =================================================================== --- src/color.c (revisión: 4826) +++ src/color.c (copia de trabajo) @@ -38,10 +38,38 @@ void set_colorpairs(void) { const syntaxtype *this_syntax = syntaxes; + bool bright = FALSE, defok = FALSE; + short fg, bg; + size_t i; + start_color(); + +#ifdef HAVE_USE_DEFAULT_COLORS + /* Use the default colors, if available. */ + defok = (use_default_colors() != ERR); +#endif + + for (i = 0; i < NUMBER_OF_ELEMENTS; i++) { + if (parse_color_names(specified_color_combo[i], &fg, &bg, &bright)) { + if (fg == -1 && !defok) + fg = COLOR_WHITE; + if (bg == -1 && !defok) + bg = COLOR_BLACK; + init_pair(i + 1, fg, bg); + interface_color_pair[i] = COLOR_PAIR(i + 1); + } + else if (i != FUNCTION_TAG) + interface_color_pair[i] = reverse_attr; + + if (specified_color_combo[i] != NULL) { + free(specified_color_combo[i]); + specified_color_combo[i] = NULL; + } + } + for (; this_syntax != NULL; this_syntax = this_syntax->next) { colortype *this_color = this_syntax->color; - int color_pair = 1; + int color_pair = NUMBER_OF_ELEMENTS + 1; for (; this_color != NULL; this_color = this_color->next) { const colortype *beforenow = this_syntax->color; @@ -71,14 +99,8 @@ if (has_colors()) { const colortype *tmpcolor; #ifdef HAVE_USE_DEFAULT_COLORS - bool defok; -#endif - - start_color(); - -#ifdef HAVE_USE_DEFAULT_COLORS /* Use the default colors, if available. */ - defok = (use_default_colors() != ERR); + bool defok = (use_default_colors() != ERR); #endif for (tmpcolor = openfile->colorstrings; tmpcolor != NULL; Index: src/prompt.c =================================================================== --- src/prompt.c (revisión: 4826) +++ src/prompt.c (copia de trabajo) @@ -853,7 +853,7 @@ index = strnlenpt(curranswer, index); page_start = get_statusbar_page_start(start_col, start_col + index); - wattron(bottomwin, reverse_attr); + wattron(bottomwin, interface_color_pair[TITLE_BAR]); blank_statusbar(); @@ -866,7 +866,7 @@ waddstr(bottomwin, expanded); free(expanded); - wattroff(bottomwin, reverse_attr); + wattroff(bottomwin, interface_color_pair[TITLE_BAR]); statusbar_pww = statusbar_xplustabs(); reset_statusbar_cursor(); wnoutrefresh(bottomwin); @@ -1273,12 +1273,12 @@ onekey("^C", _("Cancel"), width); } - wattron(bottomwin, reverse_attr); + wattron(bottomwin, interface_color_pair[TITLE_BAR]); blank_statusbar(); mvwaddnstr(bottomwin, 0, 0, msg, actual_x(msg, COLS - 1)); - wattroff(bottomwin, reverse_attr); + wattroff(bottomwin, interface_color_pair[TITLE_BAR]); /* Refresh the edit window and the statusbar before getting * input. */ Index: src/winio.c =================================================================== --- src/winio.c (revisión: 4826) +++ src/winio.c (copia de trabajo) @@ -2104,7 +2104,7 @@ assert(path != NULL || openfile->filename != NULL); - wattron(topwin, reverse_attr); + wattron(topwin, interface_color_pair[TITLE_BAR]); blank_titlebar(); @@ -2235,7 +2235,7 @@ } } - wattroff(topwin, reverse_attr); + wattroff(topwin, interface_color_pair[TITLE_BAR]); wnoutrefresh(topwin); reset_cursor(); @@ -2306,12 +2306,12 @@ start_x = (COLS - foo_len - 4) / 2; wmove(bottomwin, 0, start_x); - wattron(bottomwin, reverse_attr); + wattron(bottomwin, interface_color_pair[STATUS_BAR]); waddstr(bottomwin, "[ "); waddstr(bottomwin, foo); free(foo); waddstr(bottomwin, " ]"); - wattroff(bottomwin, reverse_attr); + wattroff(bottomwin, interface_color_pair[STATUS_BAR]); wnoutrefresh(bottomwin); reset_cursor(); wnoutrefresh(edit); @@ -2411,9 +2411,9 @@ assert(keystroke != NULL && desc != NULL); - wattron(bottomwin, reverse_attr); + wattron(bottomwin, interface_color_pair[KEY_COMBO]); waddnstr(bottomwin, keystroke, actual_x(keystroke, len)); - wattroff(bottomwin, reverse_attr); + wattroff(bottomwin, interface_color_pair[KEY_COMBO]); if (len > keystroke_len) len -= keystroke_len; @@ -2421,8 +2421,10 @@ len = 0; if (len > 0) { + wattron(bottomwin, interface_color_pair[FUNCTION_TAG]); waddch(bottomwin, ' '); waddnstr(bottomwin, desc, actual_x(desc, len)); + wattroff(bottomwin, interface_color_pair[FUNCTION_TAG]); } } Index: src/nano.c =================================================================== --- src/nano.c (revisión: 4826) +++ src/nano.c (copia de trabajo) @@ -2657,6 +2657,15 @@ mouse_init(); #endif +#ifndef DISABLE_COLOR + set_colorpairs(); +#else + interface_color_pair[TITLE_BAR] = reverse_attr; + interface_color_pair[STATUS_BAR] = reverse_attr; + interface_color_pair[KEY_COMBO] = reverse_attr; + interface_color_pair[FUNCTION_TAG] = A_NORMAL; +#endif + #ifdef DEBUG fprintf(stderr, "Main: open file\n"); #endif