color: default to dark color theme
Subsystems (3)
PATCH 1/1 color: default to dark color theme
From: Matteo Croce <[email protected]>
The majority of Linux terminals are using a dark background. iproute2 tries to detect the color theme via the COLORFGBG environment variable, and defaults to light background if not set.
Change the default behaviour to dark background, and while at it change the current logic which assumes that the color code is a single digit.
Signed-off-by Matteo Croce <[email protected]>
--- lib/color.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
lib/color.c +11 -10
@@ -72,7 +72,7 @@ static enum color attr_colors_dark[] = { C_CLEAR }; -static int is_dark_bg; +static int is_light_bg;static int color_is_enabled;static void enable_color (void )
@@ -124,14 +124,15 @@ static void set_color_palette(void)char *p =getenv ("COLORFGBG" );/* -* COLORFGBG environment variable usually contains either two or three -* values separated by semicolons; we want the last value in either case. -* If this value is 0-6 or 8, background is dark. +* COLORFGBG environment variable usually contains either two or three values +* separated by semicolons: if this value is 0-6 or 8, background is dark. */ -if (p && (p =strrchr (p,';' )) !=NULL - && ((p[1 ] >='0' && p[1 ] <='6' ) || p[1 ] =='8' ) - && p[2 ] =='\0' ) - is_dark_bg =1 ; +if (p && (p =strrchr (p,';' )) !=NULL ) { +int bg =atoi (p +1 ); + +if (bg ==7 || (bg >=9 && bg <=15 )) + is_light_bg =1 ; + } } __attribute__((format(printf, 3, 4)))
@@ -150,8 +151,8 @@ int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...) goto end; } - ret +=fprintf (fp,"%s" , color_codes[is_dark_bg ? - attr_colors_dark[attr] : attr_colors_light[attr]]); + ret +=fprintf (fp,"%s" , color_codes[is_light_bg ? + attr_colors_light[attr] : attr_colors_dark[attr]]); ret +=vfprintf (fp, fmt, args); ret +=fprintf (fp,"%s" , color_codes[C_CLEAR ]);
Signature · 1 line
2.48.1