@@ -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 disable_color(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);
@@ -89,6 +89,11 @@ void set_color_palette(void)
is_dark_bg = 1;
}
+void disable_color(void)
+{
+ color_is_enabled = 0;
+}
+
int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
{
int ret = 0;
@@ -96,13 +101,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]);