>From aa818317439d03f3fbf29a74457a92cc6d88e79a Mon Sep 17 00:00:00 2001 From: Brand Huntsman Date: Mon, 26 Feb 2018 21:33:14 -0700 Subject: [PATCH 4/5] italic, reverse and underline attributes Signed-off-by: Brand Huntsman --- src/rcfile.c | 38 +++++++++++++++++++++++++++++++++----- syntax/nanorc.nanorc | 4 ++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/rcfile.c b/src/rcfile.c index 18e4d2e4..17ba1b0e 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -854,6 +854,14 @@ static char *find_next_comma_word(char *text) return comma + 1; } +/* Set attribute or warn if already set. */ +static void set_attribute(int *attributes, int value) +{ + if (*attributes & value) + rcfile_error(N_("A color should not use the same attribute more than once")); + *attributes |= value; +} + /* Parse the color name, or pair of color names, in combostr. */ bool parse_color_names(char *combostr, short *fg, short *bg, int *attributes) { @@ -863,11 +871,31 @@ bool parse_color_names(char *combostr, short *fg, short *bg, int *attributes) *attributes = A_NORMAL; - /* If the specified color starts with "bold,", set the bold attribute. - * The bold attribute makes named colors bold and bright, or only bright - * on terminals without bold support, or only bold for extended colors. */ - if (word != NULL && strcasecmp(word, "bold") == 0) { - *attributes |= A_BOLD; + /* Get attributes. */ + while (word != NULL) { + if (strcasecmp(word, "bold") == 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) { + /* 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); + #else + rcfile_error(N_("The italic color attribute requires ncurses >= 6.0")); + #endif + } else if (strcasecmp(word, "reverse") == 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) { + /* The underline attribute makes the color underlined. */ + set_attribute(attributes, A_UNDERLINE); + } else + break; word = next_word; next_word = find_next_comma_word(word); diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc index 6c5a107c..98994722 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|(bold,)?(#([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),)*(#([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|(bold,)?(#([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),)*(#([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