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.
This commit is contained in:
Benno Schulenberg 2022-03-01 11:41:16 +01:00
parent ed60e16974
commit 67adef8f6c
4 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;