>From e30fa67ce7f759fe86f439c9191d2fd9312e03e4 Mon Sep 17 00:00:00 2001 From: Brand Huntsman Date: Thu, 15 Feb 2018 15:00:27 -0700 Subject: [PATCH 3/6] index colors Signed-off-by: Brand Huntsman --- src/rcfile.c | 30 ++++++++++++++++++++++++++++-- syntax/nanorc.nanorc | 4 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/rcfile.c b/src/rcfile.c index c2f343d6..cab54694 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -586,11 +586,37 @@ void parse_includes(char *ptr) * and set bright to TRUE if that color has bright prefix. */ short color_to_short(const char *colorname, bool *bright) { + *bright = FALSE; + + /* Index colors are numeric values from 0 to nr_term_colors-1. + * These are are not portable between terminals with different + * color counts. */ + if (*colorname >= '0' && *colorname <= '9') { + ssize_t result = -1; + parse_num(colorname, &result); + if (result < 0) { + rcfile_error(N_("Color \"%s\" not understood"), colorname); + return -1; + } + if (result >= nr_term_colors && result > 15) { + /* Allow 8-15 indices on 8-color terminals. */ + rcfile_error(N_("Color index \"%s\" must be 0 to %d"), + colorname, nr_term_colors-1); + return -1; + } + + if (result < 8) + return result; + + /* Indices 8-15 are bright variants of 0-7. */ + *bright = TRUE; + return result - 8; + } + if (strncasecmp(colorname, "bright", 6) == 0) { *bright = TRUE; colorname += 6; - } else - *bright = FALSE; + } if (strcasecmp(colorname, "green") == 0) return COLOR_GREEN; diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc index a77a6c9a..bfa6eca9 100644 --- a/syntax/nanorc.nanorc +++ b/syntax/nanorc.nanorc @@ -8,7 +8,7 @@ icolor brightred "^[[:space:]]*((un)?(bind|set)|include|syntax|header|magic|comm # 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|(bold,)?((bright)?(white|black|red|blue|green|yellow|magenta|cyan))?(,(white|black|red|blue|green|yellow|magenta|cyan))?)\>" +icolor yellow "^[[:space:]]*set[[:space:]]+((function|key|number|selected|status|title)color)[[:space:]]+(bold|(bold,)?((bright)?(white|black|red|blue|green|yellow|magenta|cyan)|[0-9]+)?(,(white|black|red|blue|green|yellow|magenta|cyan|[0-9]+))?)\>" 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:]]*$)" @@ -20,7 +20,7 @@ icolor green "^[[:space:]]*((un)?(bind|set)|include|syntax|header|magic|comment| color brightmagenta "".+"([[:space:]]|$)" # Colors -icolor yellow "^[[:space:]]*i?color[[:space:]]+(bold|(bold,)?((bright)?(white|black|red|blue|green|yellow|magenta|cyan))?(,(white|black|red|blue|green|yellow|magenta|cyan))?)\>" +icolor yellow "^[[:space:]]*i?color[[:space:]]+(bold|(bold,)?((bright)?(white|black|red|blue|green|yellow|magenta|cyan)|[0-9]+)?(,(white|black|red|blue|green|yellow|magenta|cyan|[0-9]+))?)\>" icolor magenta "^[[:space:]]*i?color\>" "\<(start|end)=" # Comments -- 2.13.6