nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 67adef8f6c44be44a00ac975ebb1764296d378a8
parent ed60e1697442778a8131a753a0785514b192f0ec
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue,  1 Mar 2022 11:41:16 +0100

display: suppress spotlight yellow and error red when NO_COLOR is set

This makes nano conform to the https://no-color.org/ idea: suppressing
any color in the output (in the default setup) when NO_COLOR is set in
the environment.

Specifying a color for any interface element will, however, re-enable
also yellow for the spotlight and red for error messages.

Diffstat:
Msrc/color.c | 6++++++
Msrc/global.c | 2++
Msrc/nano.c | 3+++
Msrc/prototypes.h | 1+
4 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/color.c b/src/color.c @@ -53,6 +53,7 @@ void set_interface_colorpairs(void) } init_pair(index + 1, combo->fg, combo->bg); interface_color_pair[index] = COLOR_PAIR(index + 1) | combo->attributes; + rescind_colors = FALSE; } else { if (index == FUNCTION_TAG || index == SCROLL_BAR) interface_color_pair[index] = A_NORMAL; @@ -72,6 +73,11 @@ void set_interface_colorpairs(void) free(color_combo[index]); } + + if (rescind_colors) { + interface_color_pair[SPOTLIGHTED] = A_REVERSE; + interface_color_pair[ERROR_MESSAGE] = A_REVERSE; + } } /* Assign a pair number to each of the foreground/background color combinations diff --git a/src/global.c b/src/global.c @@ -201,6 +201,8 @@ char *syntaxstr = NULL; /* The color syntax name specified on the command line. */ bool have_palette = FALSE; /* Whether the colors for the current syntax have been initialized. */ +bool rescind_colors = FALSE; + /* Becomes TRUE when NO_COLOR is set in the environment. */ #endif int currmenu = MMOST; diff --git a/src/nano.c b/src/nano.c @@ -2087,6 +2087,9 @@ int main(int argc, char **argv) /* If the terminal can do colors, tell ncurses to switch them on. */ if (has_colors()) start_color(); + + /* When requested, suppress the default spotlight and error colors. */ + rescind_colors = (getenv("NO_COLOR") != NULL); #endif /* Set up the function and shortcut lists. This needs to be done diff --git a/src/prototypes.h b/src/prototypes.h @@ -141,6 +141,7 @@ extern char *alt_speller; extern syntaxtype *syntaxes; extern char *syntaxstr; extern bool have_palette; +extern bool rescind_colors; #endif extern bool refresh_needed;