Index: doc/man/nanorc.5 =================================================================== --- doc/man/nanorc.5 (revision 5095) +++ doc/man/nanorc.5 (working copy) @@ -236,6 +236,8 @@ Valid color names for foreground and background are: .BR white , \ black , \ red , \ blue , \ green , \ yellow , \ magenta ", and " cyan . And either "\fIfgcolor\fR" or ",\fIbgcolor\fR" may be left out. +Extended colors can be used with color??? where ??? = number of the color. This +only works if the terminal supports it. .TP .B set view Disallow file modification. Index: doc/nanorc.sample.in =================================================================== --- doc/nanorc.sample.in (revision 5095) +++ doc/nanorc.sample.in (working copy) @@ -209,7 +209,8 @@ ## ## Valid colors: white, black, red, blue, green, yellow, magenta, cyan. ## For foreground colors, you may use the prefix "bright" to get a -## stronger highlight. +## stronger highlight. Extended colors can be used with color??? where +## ??? = number of the color. This only works if the terminal supports it. ## ## To use multi-line regexes, use the start="regex" end="regex" ## [start="regex" end="regex"...] format. Index: src/global.c =================================================================== --- src/global.c (revision 5095) +++ src/global.c (working copy) @@ -159,6 +159,8 @@ /* The global list of color syntaxes. */ char *syntaxstr = NULL; /* The color syntax name specified on the command line. */ +bool enable_extended_colors = FALSE; + /* Do we have support for more then 16 colors? */ #endif bool edit_refresh_needed = FALSE; Index: src/nano.c =================================================================== --- src/nano.c (revision 5095) +++ src/nano.c (working copy) @@ -2479,6 +2479,13 @@ #ifndef DISABLE_SPELLER alt_speller = NULL; #endif +#ifndef DISABLE_COLOR + /* Check terminal color capability before loading the rcfile */ + char *termenv = getenv("TERM"); + if(strcmp("xterm-256color", termenv) == 0) + enable_extended_colors = TRUE; + /* Maybe add support for more types? */ +#endif do_rcfile(); Index: src/nano.h =================================================================== --- src/nano.h (revision 5095) +++ src/nano.h (working copy) @@ -285,6 +285,8 @@ /* Regex starts and ends within this line. */ #define CWTF (1<<6) /* Something else. */ +#define MAX_COLORS 256 + /* Max number of terminal colors */ #endif /* !DISABLE_COLOR */ Index: src/proto.h =================================================================== --- src/proto.h (revision 5095) +++ src/proto.h (working copy) @@ -106,6 +106,7 @@ #ifndef DISABLE_COLOR extern syntaxtype *syntaxes; extern char *syntaxstr; +extern bool enable_extended_colors; #endif extern bool edit_refresh_needed; Index: src/rcfile.c =================================================================== --- src/rcfile.c (revision 5095) +++ src/rcfile.c (working copy) @@ -647,7 +647,21 @@ colorname += 6; } - if (strcasecmp(colorname, "green") == 0) + if (strncasecmp(colorname, "color", 5) == 0) { + colorname += 5; + mcolor = atoi(colorname); + + /* Don't set any colors if the defined color is beyond + * the capability of the terminal. Return -2 so that + * the fg color doesn't get unreadable if the bg color + * is the same. */ + if(mcolor > 7 && enable_extended_colors == FALSE) + return -2; + + if(mcolor < 0 || mcolor > MAX_COLORS) + rcfile_error(N_("Color number %s is invalid. Valid\n" + "numbers are 0-%d\n"), colorname, MAX_COLORS); + } else if (strcasecmp(colorname, "green") == 0) mcolor = COLOR_GREEN; else if (strcasecmp(colorname, "red") == 0) mcolor = COLOR_RED; @@ -668,7 +682,8 @@ "Valid colors are \"green\", \"red\", \"blue\",\n" "\"white\", \"yellow\", \"cyan\", \"magenta\" and\n" "\"black\", with the optional prefix \"bright\"\n" - "for foreground colors."), colorname); + "for foreground colors. Or specify a color\n" + "with \"color???\""), colorname); return mcolor; } @@ -836,7 +851,7 @@ } else *bg = -1; - if (!no_fgcolor) { + if (!no_fgcolor && *bg != -2) { *fg = color_to_short(combostr, bright); /* Don't try to parse screwed-up foreground colors. */