diff -rupN original/src/color.c new/src/color.c --- original/src/color.c 2012-12-31 18:53:32.000000000 -0800 +++ new/src/color.c 2014-03-24 07:11:25.151256142 -0700 @@ -38,10 +38,42 @@ void set_colorpairs(void) { const syntaxtype *this_syntax = syntaxes; + start_color(); + + bool defok = FALSE; +#ifdef HAVE_USE_DEFAULT_COLORS + /* Use the default colors, if available. */ + defok = (use_default_colors() != ERR); +#endif + + short fg, bg; + bool bright = FALSE; + size_t np; + for (np = 0; np < NUM_MENU_COLOR_PAIRS; np++){ + + if (parse_color_string(menu_colors[np], &fg, &bg, &bright)){ + + if (fg == -1 && !defok) + fg = COLOR_WHITE; + + if (bg == -1 && !defok) + bg = COLOR_BLACK; + + init_pair(np+1, fg, bg); + menu_color_pair[np]=COLOR_PAIR(np+1); + } + else if(np != MENU_COLOR) + menu_color_pair[np]=reverse_attr; + + if(menu_colors[np] != NULL){ + free(menu_colors[np]); + menu_colors[np] = NULL; + } + } for (; this_syntax != NULL; this_syntax = this_syntax->next) { colortype *this_color = this_syntax->color; - int color_pair = 1; + int color_pair = NUM_MENU_COLOR_PAIRS+1; for (; this_color != NULL; this_color = this_color->next) { const colortype *beforenow = this_syntax->color; @@ -74,7 +106,6 @@ void color_init(void) bool defok; #endif - start_color(); #ifdef HAVE_USE_DEFAULT_COLORS /* Use the default colors, if available. */ diff -rupN original/src/global.c new/src/global.c --- original/src/global.c 2013-03-21 06:17:24.000000000 -0700 +++ new/src/global.c 2014-03-23 05:30:46.676217106 -0700 @@ -199,6 +199,10 @@ regmatch_t regmatches[10]; int reverse_attr = A_REVERSE; /* The curses attribute we use for reverse video. */ +int menu_color_pair[]={A_NORMAL}; +#ifdef ENABLE_COLOR +char* menu_colors[] = {NULL}; +#endif char *homedir = NULL; /* The user's home directory, from $HOME or /etc/passwd. */ diff -rupN original/src/nano.c new/src/nano.c --- original/src/nano.c 2013-03-21 06:17:46.000000000 -0700 +++ new/src/nano.c 2014-03-23 04:57:22.490868000 -0700 @@ -2604,6 +2604,14 @@ int main(int argc, char **argv) mouse_init(); #endif +#ifdef ENABLE_COLOR + set_colorpairs(); +#else + for (np = 0; np < NUM_MENU_COLOR_PAIRS; np++) + menu_color_pair[np]=reverse_attr; + menu_color_pair[MENU_COLOR]=A_NORMAL; +#endif + #ifdef DEBUG fprintf(stderr, "Main: open file\n"); #endif diff -rupN original/src/nano.h new/src/nano.h --- original/src/nano.h 2013-03-21 06:17:24.000000000 -0700 +++ new/src/nano.h 2014-03-23 04:21:07.734644000 -0700 @@ -470,6 +470,13 @@ typedef struct subnfunc { /* next item in the list */ } subnfunc; +enum +{ + MENU_COLOR=0, + TITLE_COLOR, + FOCUS_COLOR, + NUM_MENU_COLOR_PAIRS +}; /* Enumeration to be used in flags table. See FLAGBIT and FLAGOFF * definitions. */ diff -rupN original/src/prompt.c new/src/prompt.c --- original/src/prompt.c 2012-12-31 18:53:32.000000000 -0800 +++ new/src/prompt.c 2014-03-23 04:40:24.798629000 -0700 @@ -854,7 +854,7 @@ void update_statusbar_line(const char *c index = strnlenpt(curranswer, index); page_start = get_statusbar_page_start(start_col, start_col + index); - wattron(bottomwin, reverse_attr); + wattron(bottomwin, menu_color_pair[TITLE_COLOR]); blank_statusbar(); @@ -867,7 +867,7 @@ void update_statusbar_line(const char *c waddstr(bottomwin, expanded); free(expanded); - wattroff(bottomwin, reverse_attr); + wattroff(bottomwin, menu_color_pair[TITLE_COLOR]); statusbar_pww = statusbar_xplustabs(); reset_statusbar_cursor(); wnoutrefresh(bottomwin); @@ -1288,12 +1288,12 @@ int do_yesno_prompt(bool all, const char onekey("^C", _("Cancel"), width); } - wattron(bottomwin, reverse_attr); + wattron(bottomwin, menu_color_pair[TITLE_COLOR]); blank_statusbar(); mvwaddnstr(bottomwin, 0, 0, msg, actual_x(msg, COLS - 1)); - wattroff(bottomwin, reverse_attr); + wattroff(bottomwin, menu_color_pair[TITLE_COLOR]); /* Refresh the edit window and the statusbar before getting * input. */ diff -rupN original/src/proto.h new/src/proto.h --- original/src/proto.h 2013-03-21 06:17:24.000000000 -0700 +++ new/src/proto.h 2014-03-23 04:29:02.738829000 -0700 @@ -125,6 +125,10 @@ extern regmatch_t regmatches[10]; #endif extern int reverse_attr; +extern int menu_color_pair[NUM_MENU_COLOR_PAIRS]; +#ifdef ENABLE_COLOR +extern char* menu_colors[NUM_MENU_COLOR_PAIRS]; +#endif extern char *homedir; @@ -562,6 +566,7 @@ void parse_magic_syntax(char *ptr); void parse_include(char *ptr); short color_to_short(const char *colorname, bool *bright); void parse_colors(char *ptr, bool icase); +bool parse_color_string(const char *fgstr, short *fg, short *bg, bool *bright); void reset_multis(filestruct *fileptr, bool force); void alloc_multidata_if_needed(filestruct *fileptr); #endif diff -rupN original/src/rcfile.c new/src/rcfile.c --- original/src/rcfile.c 2013-03-21 06:17:24.000000000 -0700 +++ new/src/rcfile.c 2014-03-23 04:39:04.766932000 -0700 @@ -99,6 +99,11 @@ static const rcoption rcopts[] = { {"wordbounds", WORD_BOUNDS}, {"softwrap", SOFTWRAP}, #endif +#ifdef ENABLE_COLOR + {"focuscolor", 0}, + {"menucolor", 0}, + {"titlecolor", 0}, +#endif {NULL, 0} }; @@ -717,34 +722,15 @@ short color_to_short(const char *colorna return mcolor; } -/* Parse the color string in the line at ptr, and add it to the current - * file's associated colors. If icase is TRUE, treat the color string - * as case insensitive. */ -void parse_colors(char *ptr, bool icase) +bool parse_color_string(const char *fgstr, short *fg, short *bg, bool *bright) { - short fg, bg; - bool bright = FALSE, no_fgcolor = FALSE; - char *fgstr; - - assert(ptr != NULL); - - if (syntaxes == NULL) { - rcfile_error( - N_("Cannot add a color command without a syntax command")); - return; - } - - if (*ptr == '\0') { - rcfile_error(N_("Missing color name")); - return; - } - - fgstr = ptr; - ptr = parse_next_word(ptr); + bool no_fgcolor = FALSE; + + if (fgstr == NULL) return false; + if (strchr(fgstr, ',') != NULL) { char *bgcolorname; - strtok(fgstr, ","); bgcolorname = strtok(NULL, ","); if (bgcolorname == NULL) { @@ -757,20 +743,49 @@ void parse_colors(char *ptr, bool icase) rcfile_error( N_("Background color \"%s\" cannot be bright"), bgcolorname); - return; + return false; } - bg = color_to_short(bgcolorname, &bright); + *bg = color_to_short(bgcolorname, bright); } else - bg = -1; + *bg = -1; if (!no_fgcolor) { - fg = color_to_short(fgstr, &bright); + *fg = color_to_short(fgstr, bright); /* Don't try to parse screwed-up foreground colors. */ - if (fg == -1) - return; + if (*fg == -1) + return false; } else - fg = -1; + *fg = -1; + + return true; +} + +/* Parse the color string in the line at ptr, and add it to the current + * file's associated colors. If icase is TRUE, treat the color string + * as case insensitive. */ +void parse_colors(char *ptr, bool icase) +{ + short fg, bg; + bool bright = FALSE; + char *fgstr; + + assert(ptr != NULL); + + if (syntaxes == NULL) { + rcfile_error( + N_("Cannot add a color command without a syntax command")); + return; + } + + if (*ptr == '\0') { + rcfile_error(N_("Missing color name")); + return; + } + + fgstr = ptr; + ptr = parse_next_word(ptr); + if (!parse_color_string(fgstr, &fg, &bg, &bright)) return; if (*ptr == '\0') { rcfile_error(N_("Missing regex string")); @@ -1102,6 +1117,16 @@ void parse_rcfile(FILE *rcstream break; } +#ifdef ENABLE_COLOR + bool *bright; + if (strcasecmp(rcopts[i].name, "focuscolor") == 0) + menu_colors[FOCUS_COLOR] = option; + else if (strcasecmp(rcopts[i].name, "menucolor") == 0) + menu_colors[MENU_COLOR] = option; + else if (strcasecmp(rcopts[i].name, "titlecolor") == 0) + menu_colors[TITLE_COLOR] = option; + else +#endif #ifndef DISABLE_OPERATINGDIR if (strcasecmp(rcopts[i].name, "operatingdir") == 0) operating_dir = option; @@ -1311,9 +1336,6 @@ void do_rcfile(void) ; } -#ifdef ENABLE_COLOR - set_colorpairs(); -#endif } #endif /* ENABLE_NANORC */ diff -rupN original/src/winio.c new/src/winio.c --- original/src/winio.c 2013-03-21 06:17:46.000000000 -0700 +++ new/src/winio.c 2014-03-23 04:55:22.763436000 -0700 @@ -2113,7 +2113,7 @@ void titlebar(const char *path) assert(path != NULL || openfile->filename != NULL); - wattron(topwin, reverse_attr); + wattron(topwin, menu_color_pair[TITLE_COLOR]); blank_titlebar(); @@ -2244,7 +2244,7 @@ void titlebar(const char *path) } } - wattroff(topwin, reverse_attr); + wattroff(topwin, menu_color_pair[TITLE_COLOR]); wnoutrefresh(topwin); reset_cursor(); @@ -2313,12 +2313,12 @@ void statusbar(const char *msg, ...) start_x = (COLS - foo_len - 4) / 2; wmove(bottomwin, 0, start_x); - wattron(bottomwin, reverse_attr); + wattron(bottomwin, menu_color_pair[FOCUS_COLOR]); waddstr(bottomwin, "[ "); waddstr(bottomwin, foo); free(foo); waddstr(bottomwin, " ]"); - wattroff(bottomwin, reverse_attr); + wattroff(bottomwin, menu_color_pair[FOCUS_COLOR]); wnoutrefresh(bottomwin); reset_cursor(); wnoutrefresh(edit); @@ -2418,9 +2418,9 @@ void onekey(const char *keystroke, const assert(keystroke != NULL && desc != NULL); - wattron(bottomwin, reverse_attr); + wattron(bottomwin, menu_color_pair[TITLE_COLOR]); waddnstr(bottomwin, keystroke, actual_x(keystroke, len)); - wattroff(bottomwin, reverse_attr); + wattroff(bottomwin, menu_color_pair[TITLE_COLOR]); if (len > keystroke_len) len -= keystroke_len; @@ -2428,8 +2428,10 @@ void onekey(const char *keystroke, const len = 0; if (len > 0) { + wattron(bottomwin, menu_color_pair[MENU_COLOR]); waddch(bottomwin, ' '); waddnstr(bottomwin, desc, actual_x(desc, len)); + wattroff(bottomwin, menu_color_pair[MENU_COLOR]); } }