>From 9e5bc88b928bf2032dd9430488a83f172e469b5e Mon Sep 17 00:00:00 2001 From: Brand Huntsman Date: Tue, 27 Feb 2018 01:28:04 -0700 Subject: [PATCH 5/5] fallback attributes Signed-off-by: Brand Huntsman --- src/rcfile.c | 40 +++++++++++++++++++++++++++++++--------- syntax/nanorc.nanorc | 4 ++-- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/rcfile.c b/src/rcfile.c index 17ba1b0e..d3f64f4b 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -855,8 +855,24 @@ static char *find_next_comma_word(char *text) } /* Set attribute or warn if already set. */ -static void set_attribute(int *attributes, int value) +static void set_attribute(char *word, int end, bool fallback, + int *attributes, int value) { + bool extended = FALSE; + if (!strcmp(&word[end], ":")) { + if (fallback) { + rcfile_error(N_("Color \"%s\" not understood"), word - 1); + return; + } + extended = TRUE; + } else if (word[end] != '\0') { + rcfile_error(N_("Color \"%s\" not understood"), word); + return; + } + + if (extended && nr_term_colors <= 16) return; + if (fallback && nr_term_colors > 16) return; + if (*attributes & value) rcfile_error(N_("A color should not use the same attribute more than once")); *attributes |= value; @@ -873,27 +889,33 @@ bool parse_color_names(char *combostr, short *fg, short *bg, int *attributes) /* Get attributes. */ while (word != NULL) { - if (strcasecmp(word, "bold") == 0) { + bool fallback = FALSE; + if (*word == ':') { + fallback = TRUE; + word++; + } + + if (strncasecmp(word, "bold", 4) == 0) { /* The bold attribute makes named colors bold and bright, * or only bright on terminals without bold support, * or only bold for extended colors. */ - set_attribute(attributes, A_BOLD); - } else if (strcasecmp(word, "italic") == 0) { + set_attribute(word, 4, fallback, attributes, A_BOLD); + } else if (strncasecmp(word, "italic", 6) == 0) { /* The italic attribute makes the color italic * on terminals with italic support and an italic capable font. */ #ifdef A_ITALIC - set_attribute(attributes, A_ITALIC); + set_attribute(word, 6, fallback, attributes, A_ITALIC); #else rcfile_error(N_("The italic color attribute requires ncurses >= 6.0")); #endif - } else if (strcasecmp(word, "reverse") == 0) { + } else if (strncasecmp(word, "reverse", 7) == 0) { /* The reverse attribute swaps the foreground and background colors. * Useful when default background color is needed. * Example: color reverse,blue */ - set_attribute(attributes, A_REVERSE); - } else if (strcasecmp(word, "underline") == 0) { + set_attribute(word, 7, fallback, attributes, A_REVERSE); + } else if (strncasecmp(word, "underline", 9) == 0) { /* The underline attribute makes the color underlined. */ - set_attribute(attributes, A_UNDERLINE); + set_attribute(word, 9, fallback, attributes, A_UNDERLINE); } else break; diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc index 98994722..2660d506 100644 --- a/syntax/nanorc.nanorc +++ b/syntax/nanorc.nanorc @@ -13,7 +13,7 @@ color brightblue "^[[:space:]]*(set|unset|bind|unbind).*[[:space:]]+#.*$" # Keywords icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|casesensitive|constantshow|cutfromcursor|fill[[:space:]]+-?[[:digit:]]+|historylog|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|showcursor|smarthome|smooth|softwrap|suspend|tabsize[[:space:]]+[1-9][0-9]*|tabstospaces|tempfile|trimblanks|unix|view|wordbounds)\>" -icolor yellow "^[[:space:]]*set[[:space:]]+((error|function|key|number|selected|status|title)color)[[:space:]]+((bold|italic|reverse|underline)(,(bold|italic|reverse|underline))*|((bold|italic|reverse|underline),)*(#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3}):((bright)?(white|black|red|blue|green|yellow|magenta|cyan))?|(bright)?(white|black|red|blue|green|yellow|magenta|cyan))?(,(#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3}):(white|black|red|blue|green|yellow|magenta|cyan)?|(white|black|red|blue|green|yellow|magenta|cyan)))?)(,|[[:space:]]|$)" +icolor yellow "^[[:space:]]*set[[:space:]]+((error|function|key|number|selected|status|title)color)[[:space:]]+(((bold|italic|reverse|underline)|(bold|italic|reverse|underline):|:(bold|italic|reverse|underline))(,((bold|italic|reverse|underline)|(bold|italic|reverse|underline):|:(bold|italic|reverse|underline)))*|(((bold|italic|reverse|underline)|(bold|italic|reverse|underline):|:(bold|italic|reverse|underline)),)*(#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3}):((bright)?(white|black|red|blue|green|yellow|magenta|cyan))?|(bright)?(white|black|red|blue|green|yellow|magenta|cyan))?(,(#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3}):(white|black|red|blue|green|yellow|magenta|cyan)?|(white|black|red|blue|green|yellow|magenta|cyan)))?)(,|[[:space:]]|$)" icolor brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|errorcolor|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|punct|quotestr|selectedcolor|speller|statuscolor|titlecolor|whitespace|wordchars)[[:space:]]+" icolor brightgreen "^[[:space:]]*bind[[:space:]]+((\^([[:alpha:]]|[]0-9\^_]|Space)|M-([[:alpha:]]|[]!"#$%&'()*+,./0-9:;<=>address@hidden|}~-]|Space))|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+[[:alpha:]]+[[:space:]]+(all|main|search|replace(with)?|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)" icolor brightgreen "^[[:space:]]*unbind[[:space:]]+((\^([[:alpha:]]|[]0-9\^_]|Space)|M-([[:alpha:]]|[]!"#$%&'()*+,./0-9:;<=>address@hidden|}~-]|Space))|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+(all|main|search|replace(with)?|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)" @@ -25,7 +25,7 @@ icolor green "^[[:space:]]*((un)?(bind|set)|include|syntax|header|magic|comment| color brightmagenta "".+"([[:space:]]|$)" # Colors -icolor yellow "^[[:space:]]*i?color[[:space:]]+((bold|italic|reverse|underline)(,(bold|italic|reverse|underline))*|((bold|italic|reverse|underline),)*(#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3}):((bright)?(white|black|red|blue|green|yellow|magenta|cyan))?|(bright)?(white|black|red|blue|green|yellow|magenta|cyan))?(,(#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3}):(white|black|red|blue|green|yellow|magenta|cyan)?|(white|black|red|blue|green|yellow|magenta|cyan)))?)(,|[[:space:]]|$)" +icolor yellow "^[[:space:]]*i?color[[:space:]]+(((bold|italic|reverse|underline)|(bold|italic|reverse|underline):|:(bold|italic|reverse|underline))(,((bold|italic|reverse|underline)|(bold|italic|reverse|underline):|:(bold|italic|reverse|underline)))*|(((bold|italic|reverse|underline)|(bold|italic|reverse|underline):|:(bold|italic|reverse|underline)),)*(#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3}):((bright)?(white|black|red|blue|green|yellow|magenta|cyan))?|(bright)?(white|black|red|blue|green|yellow|magenta|cyan))?(,(#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3}):(white|black|red|blue|green|yellow|magenta|cyan)?|(white|black|red|blue|green|yellow|magenta|cyan)))?)(,|[[:space:]]|$)" icolor magenta "^[[:space:]]*i?color\>" "\<(start|end)=" # Comments -- 2.16.1