From 87fe73ddaa196b843d316682a2dafd9f55117e41 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 2 Feb 2021 14:50:45 +0100 Subject: [PATCH] color: give highlighted text its own color, to not look like marked text Now that a search match gets highlighted, the unsuspecting user might think that the text is selected, because it is colorized the same way as selected text. Avoid this by colorizing a highlighted search match with its own specific color, black on yellow by default. --- src/color.c | 5 ++++- src/definitions.h | 1 + src/nano.c | 1 + src/rcfile.c | 3 +++ src/winio.c | 4 ++-- syntax/nanorc.nanorc | 4 ++-- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/color.c b/src/color.c index 1ce89ddc..c41d3d10 100644 --- a/src/color.c +++ b/src/color.c @@ -58,7 +58,10 @@ void set_interface_colorpairs(void) interface_color_pair[index] = A_NORMAL; else if (index == GUIDE_STRIPE) interface_color_pair[index] = A_REVERSE; - else if (index == PROMPT_BAR) + else if (index == HIGHLIGHTED) { + init_pair(index + 1, COLOR_BLACK, COLOR_YELLOW); + interface_color_pair[index] = COLOR_PAIR(index + 1); + } else if (index == PROMPT_BAR) interface_color_pair[index] = interface_color_pair[TITLE_BAR]; else if (index == ERROR_MESSAGE) { init_pair(index + 1, COLOR_WHITE, COLOR_RED); diff --git a/src/definitions.h b/src/definitions.h index f4d7774b..7345620a 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -282,6 +282,7 @@ enum { GUIDE_STRIPE, SCROLL_BAR, SELECTED_TEXT, + HIGHLIGHTED, PROMPT_BAR, STATUS_BAR, ERROR_MESSAGE, diff --git a/src/nano.c b/src/nano.c index 26be9dc9..114d29d0 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2325,6 +2325,7 @@ int main(int argc, char **argv) interface_color_pair[GUIDE_STRIPE] = A_REVERSE; interface_color_pair[SCROLL_BAR] = A_NORMAL; interface_color_pair[SELECTED_TEXT] = hilite_attribute; + interface_color_pair[HIGHLIGHTED] = hilite_attribute; interface_color_pair[PROMPT_BAR] = hilite_attribute; interface_color_pair[STATUS_BAR] = hilite_attribute; interface_color_pair[ERROR_MESSAGE] = hilite_attribute; diff --git a/src/rcfile.c b/src/rcfile.c index 00af5462..08fd9072 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -132,6 +132,7 @@ static const rcoption rcopts[] = { {"stripecolor", 0}, {"scrollercolor", 0}, {"selectedcolor", 0}, + {"highlightcolor", 0}, {"promptcolor", 0}, {"statuscolor", 0}, {"errorcolor", 0}, @@ -1557,6 +1558,8 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only) color_combo[SCROLL_BAR] = parse_interface_color(argument); else if (strcmp(option, "selectedcolor") == 0) color_combo[SELECTED_TEXT] = parse_interface_color(argument); + else if (strcmp(option, "highlightcolor") == 0) + color_combo[HIGHLIGHTED] = parse_interface_color(argument); else if (strcmp(option, "promptcolor") == 0) color_combo[PROMPT_BAR] = parse_interface_color(argument); else if (strcmp(option, "statuscolor") == 0) diff --git a/src/winio.c b/src/winio.c index df0d1336..5af964ac 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3504,11 +3504,11 @@ void spotlight(size_t from_col, size_t to_col) word = display_string(openfile->current->data, from_col, to_col - from_col, FALSE, overshoots); - wattron(edit, interface_color_pair[SELECTED_TEXT]); + wattron(edit, interface_color_pair[HIGHLIGHTED]); waddnstr(edit, word, actual_x(word, to_col)); if (overshoots) mvwaddch(edit, openfile->current_y, COLS - 1 - thebar, '>'); - wattroff(edit, interface_color_pair[SELECTED_TEXT]); + wattroff(edit, interface_color_pair[HIGHLIGHTED]); free(word); } diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc index b4864580..c161c9b1 100644 --- a/syntax/nanorc.nanorc +++ b/syntax/nanorc.nanorc @@ -8,8 +8,8 @@ color brightred ".*" # Keywords color brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|boldtext|bookstyle|breaklonglines|casesensitive|constantshow|cutfromcursor|emptyline|historylog|indicator|jumpyscrolling|linenumbers|locking|magic|minibar|mouse|multibuffer|noconvert|nohelp|nonewlines|positionlog|preserve|quickblank|rawsequences|rebinddelete|regexp|saveonexit|showcursor|smarthome|softwrap|stateflags|suspendable|tabstospaces|trimblanks|unix|wordbounds|zap)\>" -color yellow "^[[:space:]]*set[[:space:]]+((error|function|key|number|prompt|scroller|selected|status|stripe|title)color)[[:space:]]+(bold,)?(italic,)?(bright|light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte)?(,(light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte))?\>" -color brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|errorcolor|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|promptcolor|punct|quotestr|scrollercolor|selectedcolor|speller|statuscolor|stripecolor|titlecolor|whitespace|wordchars)[[:space:]]+" +color yellow "^[[:space:]]*set[[:space:]]+((error|function|highlight|key|number|prompt|scroller|selected|status|stripe|title)color)[[:space:]]+(bold,)?(italic,)?(bright|light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte)?(,(light)?(white|black|red|blue|green|yellow|magenta|cyan|normal|pink|purple|mauve|lagoon|mint|lime|peach|orange|latte))?\>" +color brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|errorcolor|functioncolor|highlightcolor|keycolor|matchbrackets|numbercolor|operatingdir|promptcolor|punct|quotestr|scrollercolor|selectedcolor|speller|statuscolor|stripecolor|titlecolor|whitespace|wordchars)[[:space:]]+" color brightgreen "^[[:space:]]*set[[:space:]]+(fill[[:space:]]+-?[[:digit:]]+|(guidestripe|tabsize)[[:space:]]+[1-9][0-9]*)\>" color brightgreen "^[[:space:]]*bind[[:space:]]+((\^([A-Za-z]|[]/@\^_`]|Space)|([Ss][Hh]-)?[Mm]-[A-Za-z]|[Mm]-([][!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|Space))|F([1-9]|1[0-9]|2[0-4])|Ins|Del)[[:space:]]+([a-z]+|".*")[[:space:]]+(main|help|search|replace(with)?|yesno|gotoline|writeout|insert|browser|whereisfile|gotodir|execute|spell|linter|all)([[:space:]]+#|[[:space:]]*$)" color brightgreen "^[[:space:]]*unbind[[:space:]]+((\^([A-Za-z]|[]/@\^_`]|Space)|([Ss][Hh]-)?[Mm]-[A-Za-z]|[Mm]-([][!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|Space))|F([1-9]|1[0-9]|2[0-4])|Ins|Del)[[:space:]]+(all|main|search|replace(with)?|yesno|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)"