From 1c1cbae6bcec3f311c4a50222b445bf13b118b46 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sat, 29 Jul 2017 13:24:42 -0500 Subject: [PATCH] small addition: allow customizing the color of selected text The new option 'set selectedcolor' applies to marked text, to the currently selected file in the file browser, and to the highlighted match during interactive search-and-replace. --- doc/nano.texi | 10 +++++++--- doc/nanorc.5 | 10 +++++++--- doc/sample.nanorc.in | 2 ++ src/browser.c | 4 ++-- src/nano.c | 1 + src/nano.h | 1 + src/rcfile.c | 3 +++ src/winio.c | 12 ++++++------ syntax/nanorc.nanorc | 2 +- 9 files changed, 30 insertions(+), 15 deletions(-) diff --git a/doc/nano.texi b/doc/nano.texi index cd27a463..dbded437 100644 --- a/doc/nano.texi +++ b/doc/nano.texi @@ -707,9 +707,9 @@ 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}, -@code{keycolor}, @code{functioncolor}, and @code{numbercolor}. +function tags, line numbers, and selected text. This can be overridden by +setting the options @code{titlecolor}, @code{statuscolor}, @code{keycolor}, +@code{functioncolor}, @code{numbercolor}, and @code{selectedcolor}. @item set brackets "@var{string}" Set the characters treated as closing brackets when justifying @@ -852,6 +852,10 @@ won't work properly with this option enabled. @item set regexp Do extended regular expression searches by default. +@item set selectedcolor @var{fgcolor},@var{bgcolor} +Use this color combination for selected text. +@xref{@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. diff --git a/doc/nanorc.5 b/doc/nanorc.5 index 3d715cfa..629312e9 100644 --- a/doc/nanorc.5 +++ b/doc/nanorc.5 @@ -79,9 +79,9 @@ 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, and selected text. This can be overridden by +setting the options \fBtitlecolor\fP, \fBstatuscolor\fP, \fBkeycolor\fP, +\fBfunctioncolor\fP, \fBnumbercolor\fP, and \fBselectedcolor\fP. .TP .B set brackets "\fIstring\fP" Set the characters treated as closing brackets when justifying @@ -220,6 +220,10 @@ won't work properly with this option enabled. .B set regexp Do extended regular expression searches by default. .TP +.B set selectedcolor \fIfgcolor\fR,\fIbgcolor\fR +Specify the color combination to use for selected text. +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. diff --git a/doc/sample.nanorc.in b/doc/sample.nanorc.in index 2b39d9ff..b6eebb15 100644 --- a/doc/sample.nanorc.in +++ b/doc/sample.nanorc.in @@ -208,12 +208,14 @@ ## These are examples; by default there are no colors. # set titlecolor brightwhite,blue # set statuscolor brightwhite,green +# 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 selectedcolor brightwhite,cyan # set numbercolor magenta # set keycolor brightmagenta # set functioncolor magenta diff --git a/src/browser.c b/src/browser.c index b5cfa80f..51ea37fa 100644 --- a/src/browser.c +++ b/src/browser.c @@ -538,7 +538,7 @@ 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_TEXT]); the_row = row; the_column = col; } @@ -610,7 +610,7 @@ 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_TEXT]); free(info); diff --git a/src/nano.c b/src/nano.c index 44b83c9d..17da37b1 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2492,6 +2492,7 @@ int main(int argc, char **argv) #else interface_color_pair[TITLE_BAR] = hilite_attribute; interface_color_pair[LINE_NUMBER] = hilite_attribute; + interface_color_pair[SELECTED_TEXT] = hilite_attribute; interface_color_pair[STATUS_BAR] = hilite_attribute; interface_color_pair[KEY_COMBO] = hilite_attribute; interface_color_pair[FUNCTION_TAG] = A_NORMAL; diff --git a/src/nano.h b/src/nano.h index c6ea016d..7c52da8b 100644 --- a/src/nano.h +++ b/src/nano.h @@ -469,6 +469,7 @@ enum { TITLE_BAR = 0, LINE_NUMBER, + SELECTED_TEXT, STATUS_BAR, KEY_COMBO, FUNCTION_TAG, diff --git a/src/rcfile.c b/src/rcfile.c index beb17420..74348f5b 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -114,6 +114,7 @@ static const rcoption rcopts[] = { #ifndef DISABLE_COLOR {"titlecolor", 0}, {"numbercolor", 0}, + {"selectedcolor", 0}, {"statuscolor", 0}, {"keycolor", 0}, {"functioncolor", 0}, @@ -1113,6 +1114,8 @@ void parse_rcfile(FILE *rcstream, bool syntax_only) specified_color_combo[TITLE_BAR] = option; else if (strcasecmp(rcopts[i].name, "numbercolor") == 0) specified_color_combo[LINE_NUMBER] = option; + else if (strcasecmp(rcopts[i].name, "selectedcolor") == 0) + specified_color_combo[SELECTED_TEXT] = option; else if (strcasecmp(rcopts[i].name, "statuscolor") == 0) specified_color_combo[STATUS_BAR] = option; else if (strcasecmp(rcopts[i].name, "keycolor") == 0) diff --git a/src/winio.c b/src/winio.c index 46581274..e3aa1221 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2650,9 +2650,9 @@ void edit_draw(filestruct *fileptr, const char *converted, paintlen = actual_x(thetext, end_col - start_col); } - wattron(edit, hilite_attribute); + wattron(edit, interface_color_pair[SELECTED_TEXT]); mvwaddnstr(edit, row, margin + start_col, thetext, paintlen); - wattroff(edit, hilite_attribute); + wattroff(edit, interface_color_pair[SELECTED_TEXT]); } } #endif /* !NANO_TINY */ @@ -3417,7 +3417,7 @@ void spotlight(bool active, size_t from_col, size_t to_col) room--; if (active) - wattron(edit, hilite_attribute); + wattron(edit, interface_color_pair[SELECTED_TEXT]); waddnstr(edit, word, actual_x(word, room)); @@ -3425,7 +3425,7 @@ void spotlight(bool active, size_t from_col, size_t to_col) waddch(edit, '$'); if (active) - wattroff(edit, hilite_attribute); + wattroff(edit, interface_color_pair[SELECTED_TEXT]); free(word); @@ -3464,12 +3464,12 @@ void spotlight_softwrapped(bool active, size_t from_col, size_t to_col) break_col - from_col, FALSE); if (active) - wattron(edit, hilite_attribute); + wattron(edit, interface_color_pair[SELECTED_TEXT]); waddnstr(edit, word, actual_x(word, break_col)); if (active) - wattroff(edit, hilite_attribute); + wattroff(edit, interface_color_pair[SELECTED_TEXT]); free(word); diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc index ac1fa4ce..8013a7f4 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|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:]]+.*$"