]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
color: add new COLOR_NONE and disable_color function
authorJulien Fortin <julien@cumulusnetworks.com>
Thu, 17 Aug 2017 17:35:48 +0000 (10:35 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 18 Aug 2017 01:02:40 +0000 (18:02 -0700)
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
include/color.h
lib/color.c

index ba0b237eb04c841375588e328538e1b5575476ff..1cd6f7d2ceaf203f3c86552b3791dcdd96f9eea2 100644 (file)
@@ -2,6 +2,7 @@
 #define __COLOR_H__ 1
 
 enum color_attr {
+       COLOR_NONE,
        COLOR_IFNAME,
        COLOR_MAC,
        COLOR_INET,
@@ -12,6 +13,7 @@ enum color_attr {
 };
 
 void enable_color(void);
+void check_if_color_enabled(void);
 void set_color_palette(void);
 int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...);
 enum color_attr ifa_family_color(__u8 ifa_family);
index 4e947500bd3b010ac5bc171ecd44167e7b101ac6..79d5e289d47acb87d37b40ebb0ba6f742045cf84 100644 (file)
@@ -89,6 +89,14 @@ void set_color_palette(void)
                is_dark_bg = 1;
 }
 
+void check_if_color_enabled(void)
+{
+       if (color_is_enabled) {
+               fprintf(stderr, "Option \"-json\" conflicts with \"-color\".\n");
+               exit(1);
+       }
+}
+
 int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
 {
        int ret = 0;
@@ -96,13 +104,13 @@ int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
 
        va_start(args, fmt);
 
-       if (!color_is_enabled) {
+       if (!color_is_enabled || attr == COLOR_NONE) {
                ret = vfprintf(fp, fmt, args);
                goto end;
        }
 
        ret += fprintf(fp, "%s",
-                      color_codes[attr_colors[is_dark_bg ? attr + 7 : attr]]);
+                      color_codes[attr_colors[is_dark_bg ? attr + 8 : attr]]);
        ret += vfprintf(fp, fmt, args);
        ret += fprintf(fp, "%s", color_codes[C_CLEAR]);