nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit b027263a37bb175c5ca716ccd7d3378def1b7609
parent 1a926d79c5cbe0b6db39b6179f457949ddde68a6
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 20 Feb 2018 09:50:54 +0100

small addition: allow customizing the color of an error message

The new option 'set errorcolor' allows the user to specify the color
combination for the status bar when an error message is displayed.

Diffstat:
Mdoc/nano.texi | 4++++
Mdoc/nanorc.5 | 4++++
Mdoc/sample.nanorc.in | 6++++--
Msrc/color.c | 9++++++---
Msrc/nano.c | 1+
Msrc/nano.h | 1+
Msrc/rcfile.c | 3+++
Msrc/winio.c | 9++++++---
Msyntax/nanorc.nanorc | 4++--
9 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/doc/nano.texi b/doc/nano.texi @@ -736,6 +736,10 @@ Note that this overrides @option{quickblank}. Use cut-from-cursor-to-end-of-line by default, instead of cutting the whole line. (The old form of this option, @code{set cut}, is deprecated.) +@item set errorcolor @var{fgcolor},@var{bgcolor} +Use this color combination for the status bar when an error message is displayed. +@xref{@code{set functioncolor}} for valid color names. + @item set fill @var{number} Hard-wrap lines at column number @var{number}. If @var{number} is 0 or less, the maximum line length will be the screen width less @var{number} columns. diff --git a/doc/nanorc.5 b/doc/nanorc.5 @@ -102,6 +102,10 @@ This overrides the option \fBquickblank\fR. Use cut-from-cursor-to-end-of-line by default, instead of cutting the whole line. (The old form of this option, '\fBset cut\fR', is deprecated.) .TP +.B set statuscolor \fIfgcolor\fR,\fIbgcolor\fR +Use this color combination for the status bar when an error message is displayed. +See \fBset titlecolor\fR for valid color names. +.TP .B set fill \fInumber\fR Hard-wrap lines at column number \fInumber\fR. If \fInumber\fR is 0 or less, the maximum line length will be the screen width less \fInumber\fP columns. diff --git a/doc/sample.nanorc.in b/doc/sample.nanorc.in @@ -200,13 +200,15 @@ ## These are examples; by default there are no colors. # set titlecolor brightwhite,blue # set statuscolor brightwhite,green +# set errorcolor brightwhite,red # set selectedcolor brightwhite,magenta # set numbercolor cyan # set keycolor cyan # set functioncolor green ## In root's .nanorc you might want to use: -# set titlecolor brightwhite,red -# set statuscolor brightwhite,red +# set titlecolor brightwhite,magenta +# set statuscolor brightwhite,magenta +# set errorcolor brightwhite,red # set selectedcolor brightwhite,cyan # set numbercolor magenta # set keycolor brightmagenta diff --git a/src/color.c b/src/color.c @@ -68,10 +68,13 @@ void set_colorpairs(void) interface_color_pair[i] = COLOR_PAIR(i + 1) | A_BANDAID | (combo->bright ? A_BOLD : A_NORMAL); } else { - if (i != FUNCTION_TAG) - interface_color_pair[i] = hilite_attribute; - else + if (i == FUNCTION_TAG) interface_color_pair[i] = A_NORMAL; + else if (i == ERROR_MESSAGE) { + init_pair(i + 1, COLOR_WHITE, COLOR_RED); + interface_color_pair[i] = COLOR_PAIR(i + 1) | A_BOLD | A_BANDAID; + } else + interface_color_pair[i] = hilite_attribute; } free(color_combo[i]); diff --git a/src/nano.c b/src/nano.c @@ -2500,6 +2500,7 @@ int main(int argc, char **argv) interface_color_pair[LINE_NUMBER] = hilite_attribute; interface_color_pair[SELECTED_TEXT] = hilite_attribute; interface_color_pair[STATUS_BAR] = hilite_attribute; + interface_color_pair[ERROR_MESSAGE] = hilite_attribute; interface_color_pair[KEY_COMBO] = hilite_attribute; interface_color_pair[FUNCTION_TAG] = A_NORMAL; #endif diff --git a/src/nano.h b/src/nano.h @@ -484,6 +484,7 @@ enum LINE_NUMBER, SELECTED_TEXT, STATUS_BAR, + ERROR_MESSAGE, KEY_COMBO, FUNCTION_TAG, NUMBER_OF_ELEMENTS diff --git a/src/rcfile.c b/src/rcfile.c @@ -115,6 +115,7 @@ static const rcoption rcopts[] = { {"numbercolor", 0}, {"selectedcolor", 0}, {"statuscolor", 0}, + {"errorcolor", 0}, {"keycolor", 0}, {"functioncolor", 0}, #endif @@ -1098,6 +1099,8 @@ void parse_rcfile(FILE *rcstream, bool syntax_only) color_combo[SELECTED_TEXT] = parse_interface_color(option); else if (strcasecmp(rcopts[i].name, "statuscolor") == 0) color_combo[STATUS_BAR] = parse_interface_color(option); + else if (strcasecmp(rcopts[i].name, "errorcolor") == 0) + color_combo[ERROR_MESSAGE] = parse_interface_color(option); else if (strcasecmp(rcopts[i].name, "keycolor") == 0) color_combo[KEY_COMBO] = parse_interface_color(option); else if (strcasecmp(rcopts[i].name, "functioncolor") == 0) diff --git a/src/winio.c b/src/winio.c @@ -2131,6 +2131,7 @@ void statusline(message_type importance, const char *msg, ...) { va_list ap; static int alerts = 0; + int colorpair; char *compound, *message; size_t start_col; bool bracketed; @@ -2169,7 +2170,9 @@ void statusline(message_type importance, const char *msg, ...) msg = _("Further warnings were suppressed"); else if (alerts < 4) beep(); - } + colorpair = interface_color_pair[ERROR_MESSAGE]; + } else + colorpair = interface_color_pair[STATUS_BAR]; lastmessage = importance; @@ -2186,14 +2189,14 @@ void statusline(message_type importance, const char *msg, ...) bracketed = (start_col > 1); wmove(bottomwin, 0, (bracketed ? start_col - 2 : start_col)); - wattron(bottomwin, interface_color_pair[STATUS_BAR]); + wattron(bottomwin, colorpair); if (bracketed) waddstr(bottomwin, "[ "); waddstr(bottomwin, message); free(message); if (bracketed) waddstr(bottomwin, " ]"); - wattroff(bottomwin, interface_color_pair[STATUS_BAR]); + wattroff(bottomwin, colorpair); /* Defeat a VTE/Konsole bug, where the cursor can go off-limits. */ if (ISSET(CONSTANT_SHOW) && ISSET(NO_HELP)) diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc @@ -8,8 +8,8 @@ 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:]]+(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" -icolor brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|punct|quotestr|selectedcolor|speller|statuscolor|titlecolor|whitespace|wordchars)[[:space:]]+" +icolor yellow "^[[:space:]]*set[[:space:]]+((error|function|key|number|selected|status|title)color)[[:space:]]+(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" +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:;<=>?@\^_`{|}~-]|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:;<=>?@\^_`{|}~-]|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:]]*$)" icolor brightgreen "^[[:space:]]*extendsyntax[[:space:]]+[[:alpha:]]+[[:space:]]+(i?color|header|magic|comment|linter|formatter)[[:space:]]+.*$"