>From ffb670f95b6b39c2a0815eb7c576f004311b8a24 Mon Sep 17 00:00:00 2001 From: Brand Huntsman Date: Fri, 19 Jan 2018 06:00:22 -0700 Subject: [PATCH] non-bold bright colors Signed-off-by: Brand Huntsman --- src/rcfile.c | 33 +++++++++++++++++++++++++-------- syntax/nanorc.nanorc | 4 ++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/rcfile.c b/src/rcfile.c index 645bbec2..b6ab3df2 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -582,11 +582,13 @@ static int hex2int(char c) return -1; } -/* Return the short value corresponding to the color named in colorname, - * and set bold to TRUE if that color has bright prefix. */ -short color_to_short(const char *colorname, bool *bold) +/* Return the short value corresponding to the color named in colorname. + * Set bold to TRUE if color has bright prefix. + * Set bright to TRUE if color has ! prefix. */ +short color_to_short(const char *colorname, bool *bold, bool *bright) { *bold = FALSE; + *bright = FALSE; /* RGB colors are #RRGGBB or #RGB hex formatted values. */ if (*colorname == '#') { @@ -637,6 +639,10 @@ short color_to_short(const char *colorname, bool *bold) * or only bright on terminals without bold support. */ *bold = TRUE; colorname += 6; + } else if (strncasecmp(colorname, "!", 1) == 0) { + /* The ! prefix makes the color bright, without bolding it. */ + *bright = TRUE; + colorname++; } if (strcasecmp(colorname, "green") == 0) @@ -851,8 +857,8 @@ bool parse_color_names(char *combostr, short *fg, short *bg, int *attributes) /* Get foreground color. */ if (word != NULL) { if (*word != '\0') { - bool fg_bold; - *fg = color_to_short(word, &fg_bold); + bool fg_bold, fg_bright; + *fg = color_to_short(word, &fg_bold, &fg_bright); /* If the specified foreground color is bad, ignore the regexes. */ if (*fg == -1) @@ -862,6 +868,14 @@ bool parse_color_names(char *combostr, short *fg, short *bg, int *attributes) if (*attributes & A_BOLD) rcfile_error(N_("A foreground color should not be bright with bold attribute")); *attributes |= A_BOLD; + } else if (fg_bright) { + if (*attributes & A_BOLD) + rcfile_error(N_("A foreground color should not be ! with bold attribute")); + /* A ! foreground on 8-color is A_BOLD to brighten it. */ + if (nr_term_colors > 8) + *fg += 8; + else + *attributes |= A_BOLD; } } else *fg = -1; @@ -871,13 +885,16 @@ bool parse_color_names(char *combostr, short *fg, short *bg, int *attributes) /* Get background color. */ if (word != NULL && *word != '\0') { - bool bg_bold; - *bg = color_to_short(word, &bg_bold); + bool bg_bold, bg_bright; + *bg = color_to_short(word, &bg_bold, &bg_bright); - if (bg_bold) { + if (bg_bold || bg_bright) { rcfile_error(N_("A background color cannot be bright")); return FALSE; } + /* It is possible to have a bright background by adding 8 to it. + * But "red,!red" becomes "red,red" on 8-color. + * Use "reverse,!red,red" for a similar result. */ } else *bg = -1; } else { diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc index a6a6be1e..beb029ed 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:]]+((function|key|number|selected|status|title)color)[[:space:]]+((bold|italic|reverse|underline)(,(bold|italic|reverse|underline))*|((bold|italic|reverse|underline),)*((bright)?(white|black|red|blue|green|yellow|magenta|cyan)|([0-9]+|#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3}))?(,(white|black|red|blue|green|yellow|magenta|cyan|[0-9]+|#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3}))?)\>" +icolor yellow "^[[:space:]]*set[[:space:]]+((function|key|number|selected|status|title)color)[[:space:]]+((bold|italic|reverse|underline)(,(bold|italic|reverse|underline))*|((bold|italic|reverse|underline),)*((!|bright)?(white|black|red|blue|green|yellow|magenta|cyan)|([0-9]+|#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3}))?(,(white|black|red|blue|green|yellow|magenta|cyan|[0-9]+|#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3}))?)\>" icolor brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|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),)*((bright)?(white|black|red|blue|green|yellow|magenta|cyan)|([0-9]+|#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3}))?(,(white|black|red|blue|green|yellow|magenta|cyan|[0-9]+|#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3}))?)\>" +icolor yellow "^[[:space:]]*i?color[[:space:]]+((bold|italic|reverse|underline)(,(bold|italic|reverse|underline))*|((bold|italic|reverse|underline),)*((!|bright)?(white|black|red|blue|green|yellow|magenta|cyan)|([0-9]+|#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3}))?(,(white|black|red|blue|green|yellow|magenta|cyan|[0-9]+|#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{3}))?)\>" icolor magenta "^[[:space:]]*i?color\>" "\<(start|end)=" # Comments -- 2.13.6