nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] small addition: allow customizing the color of an e


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] small addition: allow customizing the color of an error message
Date: Tue, 20 Feb 2018 10:19:50 +0100

The new option 'set errorcolor' allows the user to specify the color
combination for the status bar when an error message is displayed.
---
 doc/nano.texi        | 4 ++++
 doc/nanorc.5         | 4 ++++
 doc/sample.nanorc.in | 6 ++++--
 src/nano.h           | 1 +
 src/rcfile.c         | 3 +++
 src/winio.c          | 9 ++++++---
 syntax/nanorc.nanorc | 4 ++--
 7 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/doc/nano.texi b/doc/nano.texi
index b7c0e110..1d68c035 100644
--- 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.)
 
address@hidden set errorcolor @var{fgcolor},@var{bgcolor}
+Use this color combination for the status bar when an error message is 
displayed.
address@hidden@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
index c98bee86..ea13c49a 100644
--- 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
index 77744ba5..60a254b7 100644
--- 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/nano.h b/src/nano.h
index 5c25de0b..39233c4b 100644
--- 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
index 23187335..df9fdaca 100644
--- 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
index 5a5447ae..1f088466 100644
--- 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;
@@ -2165,11 +2166,13 @@ void statusline(message_type importance, const char 
*msg, ...)
                napms(1200);
 
        if (importance == ALERT) {
+               colorpair = interface_color_pair[ERROR_MESSAGE];
                if (++alerts > 3 && !ISSET(NO_PAUSES))
                        msg = _("Further warnings were suppressed");
                else if (alerts < 4)
                        beep();
-       }
+       } 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
index 12b8975a..9140c1a3 100644
--- 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:;<=>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:]]*$)"
 icolor brightgreen 
"^[[:space:]]*extendsyntax[[:space:]]+[[:alpha:]]+[[:space:]]+(i?color|header|magic|comment|linter|formatter)[[:space:]]+.*$"
-- 
2.16.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]