From: Ben Hutchings Date: Wed, 19 Mar 2025 21:51:01 +0000 (+0100) Subject: color: Introduce and use default_color_opt() function X-Git-Tag: v6.15.0~6^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=446edf9ef8055125a8ef28a9d9218b05971ee465;p=thirdparty%2Fiproute2.git color: Introduce and use default_color_opt() function As a preparatory step for supporting the NO_COLOR environment variable, replace the direct use of CONF_COLOR with a default_color_opt() function which initially returns CONF_COLOR. Signed-off-by: Ben Hutchings Signed-off-by: David Ahern --- diff --git a/bridge/bridge.c b/bridge/bridge.c index f8b5646a..d993ba19 100644 --- a/bridge/bridge.c +++ b/bridge/bridge.c @@ -103,7 +103,7 @@ static int batch(const char *name) int main(int argc, char **argv) { - int color = CONF_COLOR; + int color = default_color_opt(); while (argc > 1) { const char *opt = argv[1]; diff --git a/include/color.h b/include/color.h index 17ec56f3..b543c267 100644 --- a/include/color.h +++ b/include/color.h @@ -20,6 +20,7 @@ enum color_opt { COLOR_OPT_ALWAYS = 2 }; +int default_color_opt(void); bool check_enable_color(int color, int json); bool matches_color(const char *arg, int *val); int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...); diff --git a/ip/ip.c b/ip/ip.c index c7151fbd..e4b71bde 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -166,7 +166,7 @@ int main(int argc, char **argv) const char *libbpf_version; char *batch_file = NULL; char *basename; - int color = CONF_COLOR; + int color = default_color_opt(); /* to run vrf exec without root, capabilities might be set, drop them * if not needed as the first thing. diff --git a/lib/color.c b/lib/color.c index cd0f9f75..5c4cc329 100644 --- a/lib/color.c +++ b/lib/color.c @@ -81,6 +81,11 @@ static void enable_color(void) set_color_palette(); } +int default_color_opt(void) +{ + return CONF_COLOR; +} + bool check_enable_color(int color, int json) { if (json || color == COLOR_OPT_NEVER) diff --git a/tc/tc.c b/tc/tc.c index beb88111..0fc658c8 100644 --- a/tc/tc.c +++ b/tc/tc.c @@ -254,7 +254,7 @@ int main(int argc, char **argv) { const char *libbpf_version; char *batch_file = NULL; - int color = CONF_COLOR; + int color = default_color_opt(); int ret; while (argc > 1) {