diff --git a/include/color.h b/include/color.h index 1cd6f7d2..7fd685d0 100644 --- a/include/color.h +++ b/include/color.h @@ -2,14 +2,13 @@ #define __COLOR_H__ 1 enum color_attr { - COLOR_NONE, COLOR_IFNAME, COLOR_MAC, COLOR_INET, COLOR_INET6, COLOR_OPERSTATE_UP, COLOR_OPERSTATE_DOWN, - COLOR_CLEAR + COLOR_NONE }; void enable_color(void); diff --git a/include/json_print.h b/include/json_print.h index b6ce1f9f..dc4d2bb3 100644 --- a/include/json_print.h +++ b/include/json_print.h @@ -53,7 +53,7 @@ void close_json_array(enum output_type type, const char *delim); const char *fmt, \ type value) \ { \ - print_color_##type_name(t, -1, key, fmt, value); \ + print_color_##type_name(t, COLOR_NONE, key, fmt, value); \ } _PRINT_FUNC(int, int); _PRINT_FUNC(bool, bool); diff --git a/lib/color.c b/lib/color.c index 79d5e289..8d049a01 100644 --- a/lib/color.c +++ b/lib/color.c @@ -45,8 +45,8 @@ static const char * const color_codes[] = { NULL, }; -static enum color attr_colors[] = { - /* light background */ +/* light background */ +static enum color attr_colors_light[] = { C_CYAN, C_YELLOW, C_MAGENTA, @@ -54,8 +54,10 @@ static enum color attr_colors[] = { C_GREEN, C_RED, C_CLEAR, +}; - /* dark background */ +/* dark background */ +static enum color attr_colors_dark[] = { C_BOLD_CYAN, C_BOLD_YELLOW, C_BOLD_MAGENTA, @@ -109,8 +111,9 @@ int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...) goto end; } - ret += fprintf(fp, "%s", - color_codes[attr_colors[is_dark_bg ? attr + 8 : attr]]); + ret += fprintf(fp, "%s", color_codes[is_dark_bg ? + attr_colors_dark[attr] : attr_colors_light[attr]]); + ret += vfprintf(fp, fmt, args); ret += fprintf(fp, "%s", color_codes[C_CLEAR]); @@ -127,7 +130,7 @@ enum color_attr ifa_family_color(__u8 ifa_family) case AF_INET6: return COLOR_INET6; default: - return COLOR_CLEAR; + return COLOR_NONE; } } @@ -139,6 +142,6 @@ enum color_attr oper_state_color(__u8 state) case IF_OPER_DOWN: return COLOR_OPERSTATE_DOWN; default: - return COLOR_CLEAR; + return COLOR_NONE; } } diff --git a/testsuite/tests/ip/route/add_default_route.t b/testsuite/tests/ip/route/add_default_route.t index 0b566f1f..569ba1f8 100755 --- a/testsuite/tests/ip/route/add_default_route.t +++ b/testsuite/tests/ip/route/add_default_route.t @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh . lib/generic.sh