From b5502b605820b3633f6638322fd499f8987da12a Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sat, 29 Jul 2017 13:24:42 -0500 Subject: [PATCH] new feature: allow coloring files in the file browser Add the "unselfilecolor" nanorc option to color unselected files, and the "selfilecolor" nanorc option to color selected files, and update the documentation accordingly. sample.nanorc's example now uses colors for "selfilecolor" and "unselfilecolor" that are copied from "functioncolor" and "keycolor". --- doc/nano.texi | 16 +++++++++++++--- doc/nanorc.5 | 16 +++++++++++++--- doc/sample.nanorc.in | 4 ++++ src/browser.c | 9 ++++++--- src/color.c | 2 +- src/nano.c | 2 ++ src/nano.h | 2 ++ src/rcfile.c | 6 ++++++ syntax/nanorc.nanorc | 2 +- 9 files changed, 48 insertions(+), 11 deletions(-) diff --git a/doc/nano.texi b/doc/nano.texi index cd27a46..f18142a 100644 --- a/doc/nano.texi +++ b/doc/nano.texi @@ -707,9 +707,11 @@ Do backwards searches by default. @item set boldtext Use bold instead of reverse video for the title bar, status bar, key combos, -function tags, line numbers, and selected text. This can be overridden for -the first five by setting the options @code{titlecolor}, @code{statuscolor}, address@hidden, @code{functioncolor}, and @code{numbercolor}. +function tags, line numbers, unselected files in the browser, selected files +in the browser, and selected text. +This can be overridden for the first seven by setting the options address@hidden, @code{statuscolor}, @code{keycolor}, @code{functioncolor}, address@hidden, @code{unselfilecolor}, and @code{selfilecolor}. @item set brackets "@var{string}" Set the characters treated as closing brackets when justifying @@ -852,6 +854,10 @@ won't work properly with this option enabled. @item set regexp Do extended regular expression searches by default. address@hidden set selfilecolor @var{fgcolor},@var{bgcolor} +Use this color combination for selected files in the file browser. address@hidden@code{set functioncolor}} for valid color names. + @item set showcursor Put the cursor on the highlighted item in the file browser, to aid braille users. @@ -899,6 +905,10 @@ Save a file by default in Unix format. This overrides nano's default behavior of saving a file in the format that it had. (This option has no effect when you also use @code{set noconvert}.) address@hidden set unselfilecolor @var{fgcolor},@var{bgcolor} +Use this color combination for unselected files in the file browser. address@hidden@code{set functioncolor}} for valid color names. + @item set view Disallow file modification. diff --git a/doc/nanorc.5 b/doc/nanorc.5 index 3d715cf..bc9bb0d 100644 --- a/doc/nanorc.5 +++ b/doc/nanorc.5 @@ -79,9 +79,11 @@ Do backwards searches by default. .TP .B set boldtext Use bold instead of reverse video for the title bar, status bar, key combos, -function tags, line numbers, and selected text. This can be overridden for -the first five by setting the options \fBtitlecolor\fP, \fBstatuscolor\fP, -\fBkeycolor\fP, \fBfunctioncolor\fP, and \fBnumbercolor\fP. +function tags, line numbers, unselected files in the browser, selected files +in the browser, and selected text. +This can be overridden for the first seven by setting the options +\fBtitlecolor\fP, \fBstatuscolor\fP, \fBkeycolor\fP, \fBfunctioncolor\fP, +\fBnumbercolor\fP, \fBunselfilecolor\fP, and \fBselfilecolor\fP. .TP .B set brackets "\fIstring\fP" Set the characters treated as closing brackets when justifying @@ -220,6 +222,10 @@ won't work properly with this option enabled. .B set regexp Do extended regular expression searches by default. .TP +.B set selfilecolor \fIfgcolor\fR,\fIbgcolor\fR +Specify the color combination to use for selected files in the file browser. +See \fBset titlecolor\fR for more details. +.TP .B set showcursor Put the cursor on the highlighted item in the file browser, to aid braille users. @@ -270,6 +276,10 @@ Save a file by default in Unix format. This overrides nano's default behavior of saving a file in the format that it had. (This option has no effect when you also use \fBset noconvert\fR.) .TP +.B set unselfilecolor \fIfgcolor\fR,\fIbgcolor\fR +Specify the color combination to use for unselected files in the file browser. +See \fBset titlecolor\fR for more details. +.TP .B set view Disallow file modification. .TP diff --git a/doc/sample.nanorc.in b/doc/sample.nanorc.in index e41c6f7..18cf60a 100644 --- a/doc/sample.nanorc.in +++ b/doc/sample.nanorc.in @@ -211,12 +211,16 @@ # set numbercolor cyan # set keycolor cyan # set functioncolor green +# set unselfilecolor green +# set selfilecolor cyan ## In root's .nanorc you might want to use: # set titlecolor brightwhite,red # set statuscolor brightwhite,red # set numbercolor magenta # set keycolor brightmagenta # set functioncolor magenta +# set unselfilecolor magenta +# set selfilecolor brightmagenta ## Setup of syntax coloring. diff --git a/src/browser.c b/src/browser.c index fa11e42..9aad941 100644 --- a/src/browser.c +++ b/src/browser.c @@ -539,10 +539,11 @@ void browser_refresh(void) /* If this is the selected item, start its highlighting, and * remember its location to be able to place the cursor on it. */ if (i == selected) { - wattron(edit, hilite_attribute); + wattron(edit, interface_color_pair[SELECTED_FILE]); the_row = row; the_column = col; - } + } else + wattron(edit, interface_color_pair[UNSELECTED_FILE]); blank_row(edit, row, col, longest); @@ -611,7 +612,9 @@ void browser_refresh(void) /* If this is the selected item, finish its highlighting. */ if (i == selected) - wattroff(edit, hilite_attribute); + wattroff(edit, interface_color_pair[SELECTED_FILE]); + else + wattroff(edit, interface_color_pair[UNSELECTED_FILE]); free(info); diff --git a/src/color.c b/src/color.c index 4793974..083a82e 100644 --- a/src/color.c +++ b/src/color.c @@ -64,7 +64,7 @@ void set_colorpairs(void) interface_color_pair[i] = COLOR_PAIR(i + 1) | (bright ? A_BOLD : A_NORMAL); } else { - if (i != FUNCTION_TAG) + if (i != FUNCTION_TAG && i != UNSELECTED_FILE) interface_color_pair[i] = hilite_attribute; else interface_color_pair[i] = A_NORMAL; diff --git a/src/nano.c b/src/nano.c index 8bfa6d7..64a75c6 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2499,6 +2499,8 @@ int main(int argc, char **argv) interface_color_pair[STATUS_BAR] = hilite_attribute; interface_color_pair[KEY_COMBO] = hilite_attribute; interface_color_pair[FUNCTION_TAG] = A_NORMAL; + interface_color_pair[UNSELECTED_FILE] = A_NORMAL; + interface_color_pair[SELECTED_FILE] = hilite_attribute; #endif /* Ask ncurses for the key codes for Control+Left/Right/Up/Down. */ diff --git a/src/nano.h b/src/nano.h index c6ea016..1e18c1d 100644 --- a/src/nano.h +++ b/src/nano.h @@ -472,6 +472,8 @@ enum STATUS_BAR, KEY_COMBO, FUNCTION_TAG, + UNSELECTED_FILE, + SELECTED_FILE, NUMBER_OF_ELEMENTS }; diff --git a/src/rcfile.c b/src/rcfile.c index 069c3e2..d63379b 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -119,6 +119,8 @@ static const rcoption rcopts[] = { {"statuscolor", 0}, {"keycolor", 0}, {"functioncolor", 0}, + {"unselfilecolor", 0}, + {"selfilecolor", 0}, #endif {NULL, 0} }; @@ -1121,6 +1123,10 @@ void parse_rcfile(FILE *rcstream, bool syntax_only) specified_color_combo[KEY_COMBO] = option; else if (strcasecmp(rcopts[i].name, "functioncolor") == 0) specified_color_combo[FUNCTION_TAG] = option; + else if (strcasecmp(rcopts[i].name, "unselfilecolor") == 0) + specified_color_combo[UNSELECTED_FILE] = option; + else if (strcasecmp(rcopts[i].name, "selfilecolor") == 0) + specified_color_combo[SELECTED_FILE] = option; else #endif #ifndef DISABLE_OPERATINGDIR diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc index ac1fa4c..380ef4d 100644 --- a/syntax/nanorc.nanorc +++ b/syntax/nanorc.nanorc @@ -9,7 +9,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|justifytrim|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|unix|view|wordbounds)\>" icolor yellow "^[[:space:]]*set[[:space:]]+((function|key|number|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|speller|statuscolor|titlecolor|whitespace|wordchars)[[:space:]]+" +icolor brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|punct|quotestr|selfilecolor|speller|statuscolor|titlecolor|unselfilecolor|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.9.0