From c219e228499022b6e490c43fd398c179758acdb5 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 selected text This applies to text covered by the mark, as well as selected files in the file browser and selected matches in spotlight(). Add the "selectcolor" nanorc option to color these, and update the documentation accordingly. sample.nanorc's example now uses colors for "selectcolor" that are copied from "functioncolor" and "keycolor". --- 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 cd27a46..ba045a5 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}, address@hidden, @code{functioncolor}, and @code{numbercolor}. +function tags, line numbers, and selected text. These can be overridden by +setting the options @code{titlecolor}, @code{statuscolor}, @code{keycolor}, address@hidden, @code{numbercolor}, and @code{selectcolor}. @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. address@hidden set selectcolor @var{fgcolor},@var{bgcolor} +Use this color combination for selected text. 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. diff --git a/doc/nanorc.5 b/doc/nanorc.5 index 3d715cf..08ea235 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. These can be overridden by +setting the options \fBtitlecolor\fP, \fBstatuscolor\fP, \fBkeycolor\fP, +\fBfunctioncolor\fP, \fBnumbercolor\fP, and \fBselectcolor\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 selectcolor \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 e41c6f7..e31ef5e 100644 --- a/doc/sample.nanorc.in +++ b/doc/sample.nanorc.in @@ -211,12 +211,14 @@ # set numbercolor cyan # set keycolor cyan # set functioncolor green +# set selectcolor 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 selectcolor brightmagenta ## Setup of syntax coloring. diff --git a/src/browser.c b/src/browser.c index fa11e42..ba73001 100644 --- a/src/browser.c +++ b/src/browser.c @@ -539,7 +539,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; } @@ -611,7 +611,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 8bfa6d7..75a50a2 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2499,6 +2499,7 @@ 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[SELECTED_TEXT] = 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..52c648e 100644 --- a/src/nano.h +++ b/src/nano.h @@ -472,6 +472,7 @@ enum STATUS_BAR, KEY_COMBO, FUNCTION_TAG, + SELECTED_TEXT, NUMBER_OF_ELEMENTS }; diff --git a/src/rcfile.c b/src/rcfile.c index 069c3e2..fd83c70 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -119,6 +119,7 @@ static const rcoption rcopts[] = { {"statuscolor", 0}, {"keycolor", 0}, {"functioncolor", 0}, + {"selectcolor", 0}, #endif {NULL, 0} }; @@ -1121,6 +1122,8 @@ 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, "selectcolor") == 0) + specified_color_combo[SELECTED_TEXT] = option; else #endif #ifndef DISABLE_OPERATINGDIR diff --git a/src/winio.c b/src/winio.c index 6b727dc..426efd1 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2653,9 +2653,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 */ @@ -3420,7 +3420,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)); @@ -3428,7 +3428,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); @@ -3467,12 +3467,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 ac1fa4c..234cb6a 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|selectcolor|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.9.0